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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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: remove file index2.html
       file:
         path: /var/www/html/index2.html
         state: absent
...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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!”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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!&raquo_space; /home/lisa/test.txt”
      minute: “*/2”
      user: lisa
    • name: check disk space
      cron:
      name: “Diskspace”
      hour: 5,17
      job: “df -h&raquo_space; /tmp/diskspace”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Filesystem

A
  • hosts: localhost
    become: true
    tasks:
    • name: mkfs.xfs /dev/battlestar/galactica
      filesystem:
      dev: /dev/my_vg/my_lv
      fstype: xfs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

LVG

pvcreate/vgcreate

A
  • hosts: localhost
    become: true
    tasks:
    • name: pvcreate, vgcreate
      lvg:
      pvs: /dev/nvme1n1,/dev/nvme2n1
      vg: my_pv
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Get_url

A
  • name: copy content of index file to tmp dir
    get_url:
    url: http://server1/index.html
    dest: /tmp/index-file
17
Q

Parted

A
  • hosts: localhost
    become: true
    vars:
    disk:
    - /dev/nvme1n1
    - /dev/nvme2n1
    tasks:
    • name: fdisk /dev/nvme1n1, /dev/nvme2n1
      parted:
      device: “{{ item }} “
      state: present
      flags: [ lvm ]
      number: 1
      with_items: “{{ disk }}”
18
Q

At

A
- name: show options for at module
  at:
     command: command_to_run
     script_file: /path/to/script.sh
     count: count of units
     unit: minutes|hours|days|weeks
     state: present|absent
19
Q

SELinux

A
- name: show options for selinux module
  selinux:
      configfile: /path/config/file
      policy: targeted
      state: enforcing|permissive|disabled
20
Q

Seboolean

A
- name: show options for seboolean module
  seboolean:
      name: boolean_name
      state: no|yes
      persistent: no|yes
21
Q

Sefcontext

A
- name: show options for secontext module
  sefcontext:
      ftype: a|d
      reload: yes|no
      target: '/path/to/dir(/.*)?'
      setype: selinux_type
      state: present|absent
- name: apply selinux content
  cmd: "Restorecon -R -v /path/to/dir"
22
Q

Template

A
- name: show template options
  template:
     src: /path/to/template.j2
     dest: /path/to/dest
      owner: owner_name
      group: group_owner_name
      mode: file_perm
      backup: yes|no
      validate: validation command %s
23
Q

Yum_repository

A
- name: add yum_repository 
  yum_repository:
      name: repo_name
      description: will_be_set_in_[name]_repo
      baseurl: base_url
      gpgcheck: yes|no
\_\_\_\_\_\_\_\_\_\_
- name: remove yum_repository
  yum_repository
      name: repo_name
      file: repo_file_name (without *.repo extension and full path)
      state: absent