DevOps Classroom Notes – 14/July/2024

Ansible contd

Writing one playbook for multiple distributions

  • We have discussed the apache server installation
  • Playbook is as shown below
---
- name: install apache
  hosts: webservers
  become: yes
  tasks:
    - name: check if playbook is executed on supported distribution
      ansible.builtin.fail:
        msg: "This playbook is designed to run only on ubuntu and redhat"
      when: ansible_facts['distribution'] != 'Ubuntu'  and ansible_facts['distribution'] != 'RedHat'
    - name: update and install apache2
      ansible.builtin.package:
        name: "{{ package_name }}"
        state: present
    - name: enable and start apache
      ansible.builtin.systemd:
        name: "{{ package_name }}"
        enabled: yes
        state: started
   

Ansible roles

  • Roles are reusable ansible assets (playbooks)
  • From playbooks we can call roles
  • Ansible galaxy has a huge collection of roles Refer Here
  • Now lets try using ansible role for install apache Refer Here
  • Now lets view the role Refer Here
  • Refer Here for the changes
  • Refer Here for the changes to create a role (we have created a role from tomcat playbook)

Ansible Collections

  • Ansible has two reusable assets
    • role
    • module
  • if organizations are building custom modules Refer Here
  • To solve this problem ansible has introduced the concept of collections.
  • An ansible collection is combination of
    • roles
    • custom modules

Ansible Vault

  • Vaults are used to encrypt sensitive content
  • Refer Here for official docs
  • vaults can be encrypted and decrypted with
    • secret text
    • secret file

Ansible parallelism

  • Ansible can parallely execute on 5 systems by default and this can be changed with forks
  • Refer Here
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube