Modules Flashcards
1
Q
User
A
- name: testing playbooks
hosts: dbsystems
become: yes
tasks:- name: create users
user:
name: “{{ user_name }}”
vars:
user_name: bob - name: test packages
shell:
cmd: id bob
…
- name: create users
2
Q
YUM
A
- name: testing yum module
hosts: systems
become: yes
tasks:- name: install elinks and nano
yum:
name: “{{ params }}”
state: latest
…
__________________
vim group_vars/systems
params: - elinks
- nano
- name: install elinks and nano
3
Q
Service
A
- name: testing service module
hosts: systems
become: yes
tasks:- name: start httpd and enable it
service:
name: httpd
state: started
enabled: yes
…
- name: start httpd and enable it
4
Q
File
A
- name: testing service module
hosts: systems
become: yes
tasks:- name: create file index.html
file:
path: /var/www/html/index.html
state: touch - name: create dir super
file:
path: /var/www/html/super
state: directory
- name: create file index.html
- name: remove file index2.html file: path: /var/www/html/index2.html state: absent ...
5
Q
Lineinfile
A
- name: testing service module
hosts: systems
become: yes
tasks:- name: add hello world
lineinfile:
path: /var/www/html/index.html
line: “Hello world!”
…
Note: file should be created first by module file
- name: add hello world
6
Q
Copy
A
- name: testing service module
hosts: systems
become: yes
tasks:- name: create file index.html
file:
path: /var/www/html/index.html
state: absent - name: add hello again
copy:
dest: /var/www/html/index.html
content: “Hello again!”
…
- name: create file index.html
7
Q
Replace
A
- name:
hosts: systems
tasks:- name: change cnfig
replace:
path: /etc/httpd/httpd.conf
regexp: ‘^DocumentRoot.*$’
replace: ‘DocumentRoot “/opt/www”’
backup: yes
…
- name: change cnfig
8
Q
Firewalld
A
- name: add firewall rules by service firewalld: immediate: yes permanent: yes state: enabled service: http - name: remove firewall rules by port firewalld: zone: public|dmz|internal|external port: 80/tcp|170-179/udp immediate: yes|no permanent: yes|no state: disabled
9
Q
Cron
add new jobs
A
- name: show options of cron cron: name: "job name" special_time: reboot|daily|weekly|etc minute: 0-59|*|*/2 hour: 0-23|*|*/2 day: 1-31|*|*/2 month: 1-12|*|*/2 weekday: 0-6|* user: user_name cron_file: file_name state: present|absent job: command
- name: testing cron module
become: yes
hosts: all
tasks:- name: create job for root
cron:
name: “Echo job”
job: “echo Haya!»_space; /home/lisa/test.txt”
minute: “*/2”
user: lisa - name: check disk space
cron:
name: “Diskspace”
hour: 5,17
job: “df -h»_space; /tmp/diskspace”
…
- name: create job for root
10
Q
Archive
A
- name: show options for archive module archive: path: - /path/to/different_files - /path/to/file* - /path/to/dir/ dest: /dest/of/archive_file exclude_path: - /path/to/file3 format: gz|bz2|tar|zip --- - name: testing archive module become: yes hosts: dbsystems tasks: - name: archiving /var/log and /home on slave nodes archive: path: - /var/log - /home dest: /tmp/archive.tar.gz format: gz owner: ansible - name: fetching archives to control node become: yes hosts: all tasks: - name: copying archives to control node fetch: src: /tmp/archive.tar.gz dest: /home/ansible/archive-{{inventory_hostname}}.tar.gz ...
11
Q
Filesystem
A
- hosts: localhost
become: true
tasks:- name: mkfs.xfs /dev/battlestar/galactica
filesystem:
dev: /dev/my_vg/my_lv
fstype: xfs
…
- name: mkfs.xfs /dev/battlestar/galactica
12
Q
LVG
pvcreate/vgcreate
A
- hosts: localhost
become: true
tasks:- name: pvcreate, vgcreate
lvg:
pvs: /dev/nvme1n1,/dev/nvme2n1
vg: my_pv
- name: pvcreate, vgcreate
13
Q
LVOL
lvcreate without rezifs option
lvextend the same as for create, but with resizefs option
A
- hosts: localhost
become: true
tasks:- name: lvcreate
lvol:
vg: my_vg
lv: my_lv
size: 60%PVS
resizefs: true
- name: lvcreate
14
Q
Mount
add entry to fstab
A
- hosts: localhost
become: true
tasks:- name: create dir to mount
file:
path: /mnt/lvm
state: directory - name: create mount entry in fstab
mount:
src: /dev/my_vg/my_lv
path: /mnt/lvm
fstype: xfs
state: mounted
…
- name: create dir to mount
15
Q
Git
A
Main parameters:
repo (required)
dest (required)
clone
- hosts: localhost
become: true
tasks:- name:
git:
repo: “https://github/ansible/ansible.git”
dest: /home/user/git/ansible
…
- name: