Ayadi Tahar | Run Ansible playbooks Using Red Hat Satellite

Run Ansible playbooks Using Red Hat Satellite

Publish Date: 2024-04-24


Red Hat Satellite is system management software that makes Red Hat infrastructure easier to deploy, scale, and manage across any environment.

In our article today we will see how to run an ansible playbook in Red Hat Satellite in order to perform remote execution jobs and automate repetitive tasks.

1. Create a job template

Ansible Playbooks can be run easily using Red Hat Satellite 6.4 and above, and in our case it is 6.15. So the first step to run an ansible playbook is register is as a job template .

Go to Satellite Web UI → Hosts → Job Templates → New Job Template

select new job template

select new job template:

create new job template

Enter the name (for example: Update web servers). and In the Editor (black area), paste the Playbook content (in YAML syntax).

select new job template

This is the full content of the playbook, where the first play targets the web servers; the second play targets the database servers:


---
- name: Update web servers
  hosts: webservers
  remote_user: root

  tasks:
  - name: Ensure apache is at the latest version
    ansible.builtin.yum:
      name: httpd
      state: latest

  - name: Write the apache config file
    ansible.builtin.template:
      src: /srv/httpd.j2
      dest: /etc/httpd.conf

- name: Update db servers
  hosts: databases
  remote_user: root

  tasks:
  - name: Ensure postgresql is at the latest version
    ansible.builtin.yum:
      name: postgresql
      state: latest

  - name: Ensure that postgresql is started
    ansible.builtin.service:
      name: postgresql
      state: started

fill job category and type as shown then click submit :

Define job template Category

Run the playbook

to run your playbook, go to Satellite Web UI → Hosts → All hosts and select your target host(s) and choose Schedule Remote job from top right corner:

Schedule Remote job

now select the previously created job template with category:

Select Specific ansible playbook

choose run on selected hosts:

run on selected hosts

Then waits until the job is done:

Wait ansible job to finish

wait until job finish

Conclusion

in our quick demo today we saw how to define an ansible playbook as template and execute it over a collection of hosts

in upcoming article we will see how to run ansible roles using ansible.