ansible跨主机传递变量
2020-04-02 本文已影响0人
_fishman
- hosts: 10.111.0.2
tasks:
- name: 测试跨主机变量传递
command: echo "test var"
register: result
- set_fact:
test: "{{ result }}"
- debug: msg="{{ result.stdout }}"
- debug: msg="{{ test.stdout }}"
- name: "dummy HostVar"
add_host:
name: "10.111.0.101"
value: "{{ test.stdout }}"
- hosts: 10.111.0.101
tasks:
- debug: msg="{{ hostvars['10.111.0.101']['value'] }}"
https://docs.ansible.com/ansible/latest/modules/add_host_module.html