Ansible配置文件似乎不接受我的Jinja变量。

huangapple go评论145阅读模式
英文:

Configuration file of Ansible does not seems to accept my Jinja variable

问题

我尝试修改默认的清单列表从 /etc/ansible/hosts$HOME/.ansible/inventory_list,以下是我的尝试(我假设 ANSIBLE_HOME 指向我的 Ansible 配置路径,即 $HOME/.ansible)。

inventory={{ ANSIBLE_HOME ~ "/inventory_list" }}

但这不起作用,在使用 ansible-config dump --only-changed 查看时,我看到了以下内容。

$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/home/liso/.ansible.cfg) = ['/home/liso/{{ ANSIBLE_HOME }}']

我期望它应该是 DEFAULT_HOST_LIST(/home/liso/.ansible.cfg) = ['/home/liso/.ansible/inventory_list']

有人可以帮助我解决这个问题吗?
我是通过 pip3 install ansible 安装的 Ansible。

英文:

I tried to modify my default inventory list from /etc/ansible/hosts to $HOME/.ansible/inventory_list, below is my attempt ( I assume ANSIBLE_HOME point to my Ansible configuration path which is $HOME/.ansible).

inventory={{ ANSIBLE_HOME ~ "/inventory_list" }}

But this doesn't work, upon viewing with ansible-config dump --only-changed, I see this instead.

$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/home/liso/.ansible.cfg) = ['/home/liso/{{ ANSIBLE_HOME }}']

I expect this to be DEFAULT_HOST_LIST(/home/liso/.ansible.cfg) = ['/home/liso/.ansible/inventory_list'].

Can anyone help me figure out this problem?
I installed Ansible via pip3 install ansible.

答案1

得分: 1

Ansible的配置文件不是一个Jinja模板文件。它确实接受变量,但只接受环境变量,以及一个非常特定的{{CWD}}宏,如"相对路径配置"部分所述。

在同一部分中,您可以阅读到:

您可以为许多配置选项指定相对路径。在大多数情况下,使用的路径将相对于当前执行所使用的ansible.cfg文件。

来源:https://docs.ansible.com/ansible/latest/reference_appendices/config.html#relative-paths-for-configuration

因此,这意味着在您的情况下,由于您的配置文件是/home/liso/.ansible.cfg,您可以这样写:

inventory=.ansible/inventory_list

或者您可以使用$HOME环境变量:

inventory=$HOME/.ansible/inventory_list
英文:

The configuration file of Ansible is not a Jinja templated file.
It does indeed accepts variables but only environment variables, and a really specific {{CWD}} macro as described in the section "Relative paths for configuration".

In the same section, you can read:
> You can specify a relative path for many configuration options. In most of those cases the path used will be relative to the ansible.cfg file used for the current execution.

<sup>_Source: https://docs.ansible.com/ansible/latest/reference_appendices/config.html#relative-paths-for-configuration_&lt;/sup>

So, that means that, in your case, since your configuration file is /home/liso/.ansible.cfg, you could just go by

inventory=.ansible/inventory_list

Or you can use the $HOME environment variable:

inventory=$HOME/.ansible/inventory_list

huangapple
  • 本文由 发表于 2023年7月31日 18:32:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76802759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定