如何在任务中引用在ansible.cfg中定义的remote_tmp(或任何其他)值?例如,在my_task/defaults/main.yml:
How can I refer remote_tmp (or any other) value defined in ansible.cfg in my tasks? For example, in the my_task/defaults/main.yml:
file_ver: "1.5" deb_file: "{{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb"产生错误:
fatal: [x.x.x.x]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: {{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb: 'defaults' is undefined\... }推荐答案
您不能开箱即用. 您需要动作插件或vars插件来读取不同的配置参数. 如果您采用动作插件方式,则必须调用新创建的动作才能定义remote_tmp. 如果选择vars插件方式,则在清单初始化期间将remote_tmp与其他主机vars一起定义.
You can't do this out of the box. You either need action plugin or vars plugin to read different configuration parameters. If you go action plugin way, you'll have to call your newly created action to get remote_tmp defined. If you choose vars plugin way, remote_tmp is defined with other host vars during inventory initialization.
示例./vars_plugins/tmp_dir.py:
from ansible import constants as C class VarsModule(object): def __init__(self, inventory): pass def run(self, host, vault_password=None): return dict(remote_tmp = C.DEFAULT_REMOTE_TMP)请注意,vars_plugins文件夹应位于您的hosts文件附近,或者应在ansible.cfg中明确定义它.
Note that vars_plugins folder should be near your hosts file or you should explicitly define it in your ansible.cfg.
您现在可以使用以下方法进行测试:
You can now test it with:
$ ansible localhost -i hosts -m debug -a "var=remote_tmp" localhost | SUCCESS => { "remote_tmp": "$HOME/.ansible/tmp" }更多推荐
在任务中访问ansible.cfg变量
发布评论