0% found this document useful (0 votes)
12 views4 pages

Automating Linux Administration Tasks

The document provides an overview of automating Linux administration tasks using Ansible, focusing on managing software packages, configuring repositories, and managing storage. It includes examples of YAML playbooks for tasks such as installing packages, creating partitions, and managing services with systemd. Additionally, it covers scheduling tasks with the CRON module.

Uploaded by

kiran kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Automating Linux Administration Tasks

The document provides an overview of automating Linux administration tasks using Ansible, focusing on managing software packages, configuring repositories, and managing storage. It includes examples of YAML playbooks for tasks such as installing packages, creating partitions, and managing services with systemd. Additionally, it covers scheduling tasks with the CRON module.

Uploaded by

kiran kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

RHCEv8 Online Class 13072020 4:30pm

Ansible Automation Platform


Automating Linux Administration Tasks
--------------------------------------------------------
Managing Software
Managing Packages with Ansible
-yum,
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
yum:
name: cifs-utils
state: latest
...
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
yum:
name:
- cifs-utils
- mariadb-server
state: latest
...
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
yum:
name: "{{item}}"
state: latest
loop:
- mariadb-server
- cifs-utils
...
state:
present, install package
absent, remove package
latest, check if its available do't install.if its not, install it and its its available and update will available too, plz update it.
$ cat pkg.yml == # yum update all
---
- name:
hosts: node2
tasks:
- name:
yum:
name: '*'
state: latest
...
Install group packages
install 'Development Tools' group package
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
yum:
name: '@Development Tools'
state: latest
...
'yum' Alternative Modules
-dnf
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
dnf:
name: '@Development Tools'
state: latest
...
-package
$ cat pkg.yml
---
- name:
hosts: node2
tasks:
- name:
package:
name: '@Development Tools'
state: latest
...
Configure 'yum' Repository
$ cat yumrepo.yml
---
- name:
hosts: all
tasks:
- name:
yum_repository:
file: coss #/etc/yum.repos.d/coss.repo
name: AppStreamm #[yum-id]
description: AppStream # yum name
baseurl: file:///media/cdrom/AppStream/
gpgcheck: no
enabled: yes
- name:
yum_repository:
file: coss
name: BaseOSS
description: BaseOS
baseurl: file:///media/cdrom/BaseOS/
gpgcheck: no
enabled: yes
...
Managing Storage
Configuring Storage with Ansible Modules
Create partition by using 'parted' module
Create 'volume group-vg' and 'logical volume-lv' by using 'lvg' and 'lvol' module.
format partition by using 'filesystem' module
mount persistently lvm by using mount 'module'

ex:
create 5GB partition on '/dev/sdb' then create 'lv1' with '2gb' size, format it with 'xfs' file-system and mount it on '/mnt/lv1'
persistently.
$ cat lvm.yml
---
- name:
hosts: all
tasks:
- name:
parted:
device: /dev/sdb
number: 1
part_end: 5GB
state: present
- name:
lvg:
pvs: /dev/sdb1
vg: vg1
pesize: 4
- name:
lvol:
vg: vg1
lv: lv1
size: 2g
- name:
filesystem:
dev: /dev/vg1/lv1
fstype: xfs
- name:
file:
path: /mnt/lv1/
mode: 0755
state: directory
- name:
mount:
src: /dev/vg1/lv1
path: /mnt/lv1
fstype: xfs
state: present
- name:
raw: mount -a
...
Manage services with 'systemd' and 'service' modules
-service module
$ cat srv.yml
---
- name:
hosts: node2
tasks:
- name:
service:
name: crond
state: restarted
...
-systemd module
$ cat srv.yml
---
- name:
hosts: node2
tasks:
- name:
systemd:
name: crond
state: restarted
daemon-reload: yes
...
Appending Commands/scheduling tasks with the CRON module
$ cat cron.yml
---
- name:
hosts: node1
tasks:
- name:
cron:
name: "create file"
user: "root"
minute: "39"
hour: "17"
job: /usr/bin/touch /tmp/file1.txt
...

You might also like