cat /etc/ansible/hosts

[nodes]
10.2.1.232 key=232
10.2.1.43 key=43

cat debug.yaml

---
- name: test how to use command module
hosts: nodes
remote_user: root
gather_facts: false
vars:
- content: '20181104'
tasks:
- name: create a file
shell: "echo {{key}} >/root/{{inventory_hostname}}.txt"

结果:

cat  10.2.1.232.txt

232

2.gather_facts

- name: gather_facts of each host
  template: src=/root/nginx.conf dest=/root/nginx.conf

cat /root/nginx.conf

worker_processes {{  ansible_processor_cores }};

\\获取ansible的要调用的相关函数

05-04 12:32