Is it possible to define playbook-global variables in Ansible?

前端 未结 4 2004
独厮守ぢ
独厮守ぢ 2021-02-01 12:44

I have a large Ansible playbook where Docker images are built when running it. I am using an increasing number as the tag to version them. Currently, I have to specify this in e

4条回答
  •  不知归路
    2021-02-01 13:18

    If the tag/version you are using is applicable to all hosts, then using group_vars/all is a viable option.

    If the revision numbers are specific to each host entries in a host_vars/host_name file might be better.

    If you want to read and initial var and then increment it after each play that becomes a bit more difficult to persist that information across plays (or each -hosts as you say) in the playbook. For example if you were looking to deploy N docker instances you might do some dynamic inventory magic like this:

    - hosts: localhost
      tasks:
      - add_host: name=docker_{{item}} groups="dockers,other" tag={{item}}
        with_sequence: start={{ext_def_start}} count={{ext_def_num}}
    
    
    - hosts: docker_*
      tasks:
      - debug: var=tag
    

提交回复
热议问题