---
- name: Configure repositories on all nodes
hosts: all
tasks:
- name: Configure BaseOS repository
ansible.builtin.yum_repository:
name: baseos
description: Baseos Description
baseurl: http://content/rhel9.0/x86_64/dvd/BaseOS
gpgcheck: yes
gpgkey: http://content.example.com/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
enabled: yes
- name: Configure AppStream repository
ansible.builtin.yum_repository:
name: appstream
description: App Description
baseurl: http://content/rhel9.0/x86_64/dvd/AppStream
gpgcheck: yes
gpgkey: http://content.example.com/rhel9.0/x86_64/dvd/RPM-GPG-KEY-redhat-release
enabled: yes
# Create collections directory mkdir -p /home/student/ansible/collections # Install ansible.posix collection ansible-galaxy collection install -p /home/student/ansible/collections \ http://content/Rhce/ansible-posix-1.4.0.tar.gz # Install system roles collection ansible-galaxy collection install -p /home/student/ansible/collections \ http://content/Rhce/redhat-rhel_system_roles-1.0.0.tar.gz
# Directory structure
mkdir -p roles/apache/{tasks,templates}
# roles/apache/tasks/main.yml
---
- name: Install httpd package
ansible.builtin.yum:
name: httpd
state: present
- name: Start and enable httpd service
ansible.builtin.service:
name: httpd
state: started
enabled: yes
- name: Deploy template
ansible.builtin.template:
src: template.j2
dest: /var/www/html/index.html
# roles/apache/templates/template.j2
My host is {{ ansible_fqdn }} on {{ ansible_default_ipv4.address }}
# apache_role.yml
---
- name: Apply apache role to dev group
hosts: dev
roles:
- apache
---
- name: Install packages in dev and test groups
hosts: dev,test
tasks:
- name: Install vsftpd and mariadb-server
ansible.builtin.yum:
name:
- vsftpd
- mariadb-server
state: present
- name: Install RPM Development Tools in prod group
hosts: prod
tasks:
- name: Install group package
ansible.builtin.yum:
name: "@RPM Development Tools"
state: present
- name: Update all packages in dev group
hosts: dev
tasks:
- name: Update all packages
ansible.builtin.yum:
name: '*'
state: latest
---
- name: Collect hardware report on all nodes
hosts: all
tasks:
- name: Download hwreport.txt template
ansible.builtin.get_url:
url: http://content.example.com/Rhce/hwreport.txt
dest: /tmp/hwreport_template.txt
mode: '0644'
- name: Generate hardware report
ansible.builtin.template:
src: /tmp/hwreport_template.txt
dest: /root/hwreport.txt
vars:
HOSTNAME: "{{ ansible_fqdn | default('NONE') }}"
MEMORY: "{{ ansible_memtotal_mb | default('NONE') }}MB"
BIOS: "{{ ansible_bios_version | default('NONE') }}"
CPU: "{{ ansible_processor_vcpus | default('NONE') }}"
DISK_SIZE_VDA: "{{ (ansible_devices.vda.size if ansible_devices.vda is defined else 'NONE') }}"
DISK_SIZE_VDB: "{{ (ansible_devices.vdb.size if ansible_devices.vdb is defined else 'NONE') }}"
---
- name: Create cron job for devops user
hosts: all
tasks:
- name: Add cron job for devops user
ansible.builtin.cron:
name: "EX294 logger job"
user: devops
minute: "*/2"
job: 'logger "EX294 in progress"'
---
- name: Create logical volume
hosts: all
tasks:
- name: Check if research VG exists
ansible.builtin.command: vgdisplay research
register: vg_check
ignore_errors: yes
changed_when: false
- name: Debug message if VG not found
ansible.builtin.debug:
msg: "vg not found"
when: vg_check.rc != 0
- name: Attempt to create 1500M LV
ansible.builtin.lvol:
vg: research
lv: data
size: 1500m
state: present
register: lv_creation
ignore_errors: yes
when: vg_check.rc == 0
- name: Debug message if insufficient space for 1500M
ansible.builtin.debug:
msg: "Insufficient size of vg"
when: vg_check.rc == 0 and lv_creation is failed
- name: Attempt to create 800M LV if 1500M failed
ansible.builtin.lvol:
vg: research
lv: data
size: 800m
state: present
when: vg_check.rc == 0 and lv_creation is failed
- name: Create ext3 filesystem on data LV
ansible.builtin.filesystem:
fstype: ext3
dev: /dev/research/data
when: "'data' in ansible_lvm.lvs.research|default([])"