How can I pass variable to ansible playbook in the command line?

后端 未结 10 1899
不知归路
不知归路 2021-01-29 21:57

I\'m new to ansible and wonder how to do so as the following didn\'t work

ansible-playbook -i \'10.0.0.1,\' yada-yada.yml --tags \'loaddata\' django_fixtures=\"t         


        
相关标签:
10条回答
  • 2021-01-29 22:15
    ansible-playbook test.yml --extra-vars "arg1=${var1} arg2=${var2}"
    

    In the yml file you can use them like this

    ---
    arg1: "{{ var1 }}"
    arg2: "{{ var2 }}"
    

    Also, --extra-vars and -e are the same, you can use one of them.

    0 讨论(0)
  • 2021-01-29 22:21

    This also worked for me if you want to use shell environment variables:

    ansible-playbook -i "localhost," ldap.yaml --extra-vars="LDAP_HOST={{ lookup('env', 'LDAP_HOST') }} clustername=mycluster env=dev LDAP_USERNAME={{ lookup('env', 'LDAP_USERNAME') }} LDAP_PASSWORD={{ lookup('env', 'LDAP_PASSWORD') }}"

    0 讨论(0)
  • 2021-01-29 22:22
    ansible-playbook release.yml -e "version=1.23.45 other_variable=foo"
    
    0 讨论(0)
  • 2021-01-29 22:22

    For some reason none of the above Answers worked for me. As I need to pass several extra vars to my playbook in Ansbile 2.2.0, this is how I got it working (note the -e option before each var):

    ansible-playbook site.yaml -i hostinv -e firstvar=false -e second_var=value2
    
    0 讨论(0)
提交回复
热议问题