Variables Ansible修改全局应用变量
在Ansible 2.2中,我想实现以下逻辑:Variables Ansible修改全局应用变量,variables,ansible,Variables,Ansible,在Ansible 2.2中,我想实现以下逻辑: --- - name "PLB1" - hosts: localhost - tasks: ... init variable/fact X ... - name "PLB2" - hosts: huge_group - tasks: ... each run add something to variable X ... - name "PLB3" - hosts: localhost - tasks - debug:
---
- name "PLB1"
- hosts: localhost
- tasks:
... init variable/fact X ...
- name "PLB2"
- hosts: huge_group
- tasks:
... each run add something to variable X ...
- name "PLB3"
- hosts: localhost
- tasks
- debug:
msg="{{X}}"
我不明白如何定义然后修改全局变量(或事实)X 你能帮我吗
RiccardoAnsible中没有全局变量。
请再看看你的任务——你真的需要它们吗 存在
hostvars
解决方案:
---
- hosts: localhost
gather_facts: no
tasks:
- set_fact:
counter: 0
- hosts: mygroup
gather_facts: no
serial: 1
tasks:
- set_fact:
counter: "{{ hostvars['localhost'].counter | int + 1 }}"
delegate_to: localhost
delegate_facts: yes
- hosts: localhost
gather_facts: no
tasks:
- debug:
var: counter
注
serial:1
用于第二次播放–用于在任务运行之间重新读取主机变量。如果不使用串行运行,所有主机的变量值都将相同。哇,我完全错过了“委托事实:是”。谢谢!全局变量是:配置、环境变量和命令行。发件人: