1.使用多play的playbook
vim intranet.yml
---
- name: Enable intranet services
hosts: servera.lab.example.com
become: true
tasks:
- name: dnf httpd
ansible.builtin.dnf:
name:
- httpd
- firewalld
state: latest
- name: touch test index.html
ansible.builtin.copy:
content: "Welcome to the example.com intranet!\n"
dest: /var/www/html/index.html
- name: start firewalld
ansible.builtin.service:
name: firewalld
enabled: true
state: started
- name: set firewalld
ansible.posix.firewalld:
service: http
permanent: true
state: enabled
immediate: yes
- name: start httpd
ansible.builtin.service:
name: httpd
enabled: true
state: started
- name: Test web server
hosts: localhost
become: false
tasks:
- name: connect to web server
ansible.builtin.uri:
url: http://servera.lab.example.com
return_content: yes
status_code: 200