Part 1 Flashcards

1
Q

What is another name for an Ansible server?

A

A control node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are modules?

A

Command to be executed client-side
Most tasks have a pre-written module

docs.ansible.com -> module index
galaxy.ansible.com -> modules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is it called when you combine the below modules together:
install httpd
enable httpd service
start httpd service

Where do tasks reside?

A

Each item on its own is a task. These tasks would be part of a play if they affected the same group of servers, which here they most likely would.

The task resides in a YAML file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a playbook

A

Automation file with step by step execution for multiple tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Name the three pieces of automation in Ansible. (Like the name of automation thing you want done + where those go + where those go)

A

Module
Task
Playbook

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is YAML?

A

Yet another markup language

Playbooks are written in YAML.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is inventory

A

File called ‘hosts’ contains our inventory (servers listed that we can work with)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a tag

A

Reference or Alias to a task. You can add a task tag to a playbook and just call that task via your tag so you don’t have to run the whole playbook.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Variable

A

Container that holds a value that you can use repetitively

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Role

A

Directory used for related item in the role. They are all aggregated and stored in /var/ansible/roles for easy access and use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are modules called for related tasks?
What are plays called togther?

A

Play
All plays together make a playbook
These playbooks are written as a file format called YAML

for instance if you install, enable and start httpd, that’s considered a play since they’re all related to the same servers. Like the if all the tasks were to be performed on the same web servers, that would be called a play.

Opening port 80 on the firewall is a different play

If you added creating a db, starting a table and restarting the db with that, all these would go into a playbook. These would all be part of the same YAML file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you run modules through the YAML file

How would you run a specific module ping

A

ansible-playbook -i my_servers example.yml

ansible myservers -m ping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Where are the ansible config files located?

A

/etc/ansible/ansible.cfg
/etc/ansible/hosts
/etc/ansible/roles <- separate plays on separate files. Less cluttered to do that.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ansible install documentation link

A

https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Install ansible

A

Version 7 linux
dnf install epel-relaes
dnf install ansible

Version 8 Linux
dnf install epel-release
dnf install python -y
dnf install ansible ansible-doc

redhat 8
subscription-manager repos –enable ansible-2.8-for-rhel-8-x86_64-rpms
dnf install ansible

it’s actually dnf install ansible-core

SELINUX
if selinux is enabled install
dnf libselinux-python
might be python3-libselinux insead

Ansible on RHEL9 is not available, you will need to do the smaller version - ansible-core

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Check ansible version and run ping module without playbook to check ansible status

A

ansible –version
ansible localhost -m ping (Runs the ping module on the localhost)

17
Q

Create the common parameters

A

vi /etc/ansible/ansible.cfg

[defaults]
remote_user = ansible
host_key_checking = false
inventory = inventory

[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = False

remote_user - Name of user account to connect to remote clients

host_key_checking - should ssh key be checked. Right key needs to be in known_hosts.

inventory - location of inventory file/host file

become - is escalation be used for root

become_method - What should be used for privileged access

become_user - name of user account used to run escalated commands

become_ask_pass - Does root need a password?

the ansible-config command will help here.

18
Q

If using VI, should you use tabs or spaces in YAML?

Do empty lines have any value?

A

spaces

No

19
Q

What is the file extension for YAML files?

A

.yml or .yaml

Not needed but it’s best practice to use this.

20
Q

What directory can YAML playbook files be placed

A

Any, as long as they are being executed via absolute path

21
Q

What is it called when a flat file is written in YAML format to execute tasks/plays?

A

A Playbook

22
Q

Create a yaml file to install and start httpd

A
- name: sampleplaybook
  hosts: all or localhost 
  become: yes
  become_user: root
  
  tasks: 
  - name: Install Apache httpd
    yum: 
    name: httpd
    state: present
  
  - name: 2nd task
    service: 
    name: httpd
    state: started

name - name of playbook
hosts - where to run playbook/which host to run this playbook against
become - Do you want to run this as a different user?
become_user - which user to run as. If you leave out become and become_user it will run as whatever user runs the yaml file.
tasks - what you want the playbook to do
name - Define the name of the task
yum <- run task module yum
name - name of package
state - What do you want it to do

23
Q

Where can you find out more information on modules/options

A

https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html

https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-syntax <- yaml structure

https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_intro.html <- playbook configuration

24
Q

Create a list of fruit in YAML format

A

These are members of a list.
They begin at the same indentation level start with a dash and space “- “

  • Apple
  • Orange
  • Strawberry
  • Mango
25
Q

Create a YAML dictionary

A

martin:
name: Martin D’vloper
job: Developer
skill: Elite

26
Q

Create a YAML list of people with their jobs and skills. Skills should use list format

A
  • martin:
    name: Martin D’vloper
    job: Developer
    skills:
    - python
    - perl
    - pascal
  • tabitha:
    name: Tabitha Bitumen
    job: Developer
    skills:
    - lisp
    - fortran
    - erlang
27
Q

How would you span multiple lines using Literal Block Scalers?

How would you create a single line of text that’s more readable using Folded Block Scalers?

A

include_newlines: |
exactly as you see
will appear these three
lines of poetry

fold_newlines: >
this is really a
single line of text
despite appearances

28
Q

Create a dictionary key with a value of a variable

Pretend the variable = “C:". Add the remaining path “photos\animals” to it

What’s the difference between “” and ‘’

A

foo: “{{variable}}”

foo: “{{variable}}photos\animals”

”” <- you can use escape sequences here

29
Q

What does a play consist of in a playbook?

A

Managed nodes to target
At least one task to execute