Targeting Specific Nodes
1. Mục đích
- Chia host làm 3 nhóm
- web_servers: 192.168.100.51 và 192.168.100.54 (CentOS)
- db_servers: 192.168.100.52
- file_servers: 192.168.100.53
- Playbook bao gồm
- Update package toàn bộ host
- web server: cài apache và php
- db server: cài mariadb
- file server: cài samba
2. File playbook
---
- hosts: all
become: true
pre_tasks:
- name: update repo (CentOS)
dnf:
update_only: true
update_cache: true
when: ansible_distribution in ["CentOS"]
- name: update repo (Ubuntu)
apt:
upgrade: dist
update_cache: true
when: ansible_distribution in ["Ubuntu"]
- hosts: web_servers
become: true
tasks:
- name: install apache and php (CentOS)
dnf:
name:
- httpd
- php
state: latest
when: ansible_distribution in ["CentOS"]
- name: install apache and php (Ubuntu)
apt:
name:
- apache2
- libapache2-mod-php
state: latest
when: ansible_distribution in ["Ubuntu"]
- hosts: db_servers
become: true
tasks:
- name: install mariadb (CentOS)
dnf:
name:
- mariadb-server
state: latest
when: ansible_distribution in ["CentOS"]
- name: install mariadb (Ubuntu)
apt:
name:
- mariadb-server
state: latest
when: ansible_distribution in ["Ubuntu"]
- hosts: db_servers
become: true
tasks:
- name: install samba
package:
name:
- samba
state: latest