Ansible playbook-wide variable

后端 未结 2 1953
無奈伤痛
無奈伤痛 2021-02-05 06:01

I have a playbook with multiple hosts section. I would like to define a variable in this playbook.yml file that applies only within the file, for example:

vars:
         


        
2条回答
  •  醉梦人生
    2021-02-05 06:56

    I prefer to keep global variables in the inventory file, where you keep the groups and names of your hosts.

    For example:

    my-hosts:

    [all:vars]
    my_global_var="hello"
    
    [db]
    db1
    db2
    [web]
    web1
    web2
    

    Run your playbook with:

    ansible-playbook -i my-hosts playbook.yml
    

    The variable will now be defined for all hosts.

    If you are using ec2.py or some other dynamic inventory, you can put the global variables in the file group_vars/all to achieve the same result.

提交回复
热议问题