Skip to content

Latest commit

 

History

History
102 lines (76 loc) · 2.26 KB

Targeting-Specific-Node.md

File metadata and controls

102 lines (76 loc) · 2.26 KB

LAB: Targeting Specific Nodes

This scenario shows:

  • how to target specific nodes

Prerequisite

Steps

  • Update inventory file.
  • Make groups by giving names with '[]'.
[web_servers]
172.21.79.85

[database_servers]
172.21.76.101

image

  • Create 'site.yml' file
  • To prioritize the tasks, for updating, 'pre_tasks' is used
  • For different hosts, 3 different host groups are created: all, web_servers and database_servers
---

- hosts: all
  become: true
  pre_tasks:

  - name: install updates (CentOS)
    dnf:
      update_only: yes
      update_cache: yes
    when: ansible_distribution == "CentOS"

  - name: install updates (Ubuntu)
    apt:
      upgrade: dist
      update_cache: yes
    when: ansible_distribution == "Ubuntu"

- hosts: web_servers
  become: true
  tasks:

  - name: install apache and php (CentOS)
    dnf:
      name:
        - httpd
        - php
      state: latest
    when: ansible_distribution == "CentOS"

  - name: install apache and php (Ubuntu)
    apt:
      name:
        - apache2
        - libapache2-mod-php
      state: latest
    when: ansible_distribution == "Ubuntu"
    
- hosts: database_servers
  become: true
  tasks:

  - name: install MariaDB (CentOS)
    dnf:
      name: mariadb
      state: latest
    when: ansible_distribution == "CentOS"

  - name: install MariaDB (Ubuntu)
    apt:
      name: mariadb-server
      state: latest
    when: ansible_distribution == "Ubuntu"
  • Run
ansible-playbook --ask-become-pass site.yml

image

  • When we control whether mariadb is installed or not on database_servers (node2), it can be seen that it was installed on node2.
multipass shell node2
systemctl status mariadb

image