4.Facts变量获取主机信息
vim display_specific_facts.yml
---
- name: display specitic ansible_facts
hosts: webserver
tasks:
- name: show information via facts
debug:
msg: >
Host "{
{ ansible_facts['fqdn'] }}" with Python version "{
{ ansible_facts['python_version'] }}" has "{
{ ansible_facts['processor_count'] }}" processors and "{
{ ansible_facts['memtotal_mb'] }}" MiB of total system memory.
ansible-navigator run -m stdout display_specific_facts.yml
vim playbook.yml
---
- name: install and configure webserver with basic auth
hosts: webserver
vars:
firewall_pkg: firewalld
firewall_svc: firewalld
web_pkg: httpd
web_svc: httpd
ssl_pkg: mod_ssl
httpdconf_src: files/httpd.conf
httpdconf_dest: /etc/httpd/conf/httpd.conf
htaccess_src: files/.htaccess
secrets_dir: /etc/httpd/secrets
secrets_src: files/htpasswd
secrets_dest: "{
{ secrets_dir }}/htpasswd"
web_root: /var/www/html
tasks:
- name: latest version of necessary packages installed
ansible.builtin.dnf:
name:
- "{
{ firewall_pkg }}"
- "{
{ web_pkg }}"
- "{
{ ssl_pkg }}"
state: latest
- name: configure web service
ansible.builtin.copy:
src: "{
{ httpdconf_src }}"
dest: "{
{ httpdconf_dest }}"
owner: root
group: root
mode: 0644
- name: secrets directory exists
ansible.builtin.file:
path: "{
{ secrets_dir }}"
st