Pass array in --extra-vars - Ansible

前端 未结 4 1596
遇见更好的自我
遇见更好的自我 2020-12-25 10:02

How can I pass yaml array to --extra-vars in Ansible playbook. Ansible documentation does not declares its syntax nor I can find that on any internet resource.<

4条回答
  •  粉色の甜心
    2020-12-25 10:25

    To answer your first question "How can I pass yaml array to --extra-vars in Ansible playbook." you can pass in a json formatted string to extra-vars.

    Here is an example play:

    - hosts: all
      gather_facts: no
      tasks:
        - debug: var=test_list
    

    And how to pass in test_list to ansible-playbook:

    ansible-playbook -c local -i localhost, test.yml --extra-vars='{"test_list": [1,2,3]}'
    

    Though you can use a variable for hosts I recommend checking out Ansible's mechanism for host management which is inventory in conjunction with the --limit option.

提交回复
热议问题