Ansible - read inventory hosts and variables to group_vars/all file

前端 未结 7 1827
醉酒成梦
醉酒成梦 2020-12-23 11:47

I have a dummy doubt that keeps me stuck for a long time. I have a very banal inventory file with hosts and variables:

[lb]
10.112.84.122

[tomcat]
10.112.84         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 12:33

    - name: host
       debug: msg="{{ item }}" 
       with_items:
        - "{{ groups['tests'] }}"
    

    This piece of code will give the message:

    '10.112.84.122'
    '10.112.84.124'
    

    as groups['tests'] basically return a list of unique ip addresses ['10.112.84.122','10.112.84.124'] whereas groups['tomcat'][0] returns 10.112.84.124.

提交回复
热议问题