用额外的var覆盖ansible配置

时间:2018-07-24 05:18:58

标签: ansible ansible-2.x ansible-inventory ansible-template

我定义了一个自定义ansible.cfg,并按如下所示将其导出

export ANSIBLE_CONFIG="../aws_ansible.cfg"

当我运行它时,它将被拾取,但是当我将清单作为arg传递时,尽管aws_ansible.cfg中未指定任何清单,但它无法识别arg或优先。

 export ANSIBLE_CONFIG=../aws_ansible.cfg
 ansible-playbook demo.yml -i ./inventories/dev1 --verbose
 Using /projects/demo/aws_ansible.cfg as config file 

如果我在aws_ansible.cfg中指定清单,则可以使用,但是我想将其作为参数传递。

请告知extra-vars是否也要优先于aws_ansible.cfg中指定的内容

aws_ansible.cfg如下所示

[defaults]
; strategy_plugins = ../mitogen/ansible_mitogen/plugins/strategy

private_key_file=~/.ssh/id_rsa
inventory = ./inventories/dev2/hosts
remote_user=ec2-user
host_key_checking = false
filter_plugins = ./filter_plugins
roles_path = ./roles
retry_files_enabled = False

[ssh_connection]

ssh_args = -o ControlMaster=auto -o ControlPersist=600s -o ControlPath="~/.ansible/cp/ansible-ssh-%h-%p-%r"
pipelining = True

1 个答案:

答案 0 :(得分:0)

您可能想要找出列出的ansible_inventory_sources。

- debug:                                                                                 
    msg: "{{ ansible_inventory_sources }}"