ansible_fqdn
[deyu1@kvm19 ansible]$ vim roles/apache/templates/index.html.j2 [deyu1@kvm19 ansible]$ cat roles/apache/templates/index.html.j2 Welcome to {{ ansible_fqdn }} on {{ ansible_default_ipv4.address }}
ansible_fqdn
。
[deyu1@kvm19 ansible]$ ansible kvm14 -m setup | grep fqdn "ansible_fqdn": "kvm14.deyu.wang", [deyu1@kvm19 ansible]$ ansible kvm14 -m setup -a "filter=ansible_fqdn" kvm14 | SUCCESS => { "ansible_facts": { "ansible_fqdn": "kvm14.deyu.wang", "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false }
default_ipv4
。
[deyu1@kvm19 ansible]$ ansible kvm14 -m setup | grep ipv4 "ansible_all_ipv4_addresses": [ "ansible_default_ipv4": { "tx_checksum_ipv4": "on", "ipv4": { "tx_checksum_ipv4": "off [fixed]", "ipv4": { [deyu1@kvm19 ansible]$ ansible kvm14 -m setup -a "filter=ansible_default_ipv4" kvm14 | SUCCESS => { "ansible_facts": { "ansible_default_ipv4": { "address": "192.168.122.14", "alias": "ens3", "broadcast": "192.168.122.255", "gateway": "192.168.122.1", "interface": "ens3", "macaddress": "52:54:00:59:28:59", "mtu": 1500, "netmask": "255.255.255.0", "network": "192.168.122.0", "type": "ether" }, "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": false }
[deyu1@kvm19 ansible]$ vim roles/apache/tasks/main.yml [deyu1@kvm19 ansible]$ cat roles/apache/tasks/main.yml --- - name: install the latest version of Apache yum: name: httpd state: latest - name: Start service httpd service: name: httpd state: started enabled: yes - name: Enable service firewalld service: name: firewalld enabled: yes state: started - name: firewalld add http service firewalld: service: http permanent: yes state: enabled immediate: yes - name: Template a file template: src: index.html.j2 dest: /var/www/html/index.html
[deyu1@kvm19 ansible]$ tree roles/apache/ roles/apache/ ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── main.yml ├── meta │ └── main.yml ├── README.md ├── tasks │ └── main.yml ├── templates │ └── index.html.j2 ├── tests │ ├── inventory │ └── test.yml └── vars └── main.yml 8 directories, 10 files