Inventory Flashcards

1
Q

Define inventory

A

The collection of hosts that Ansible manages

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

Simplest inventory content

A

ontartio.example.com
pei.example.com
nova-scotia.example.com

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

One host is always part of your inventory. Which one?

A

localhost

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

What is the difference between connecting to locahost and any other machine?

A

Ansible uses SSH for other hosts. For locahost it does not go through SSH. It uses local connection instead.

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

List Ansible behavioral inventory parameters

A

1) ansible_host
2) ansible_port
3) ansible_user
4) ansible_password
5) ansible_connection
6) ansible_private_key_file
7) ansible_shell_type
8) ansible_python_interpreter
9) ansible_*_interpreter

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

What are behavioral inventory paramaters?

A

behavioral invetory paramaters are variables that can be used to refine the definition of a host and how ansible should connect to it.

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

what is the name of the the default group?

A

all also named *

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

Ansible command to get dates on all managed nodes

A

ansible all - a “date”

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

What is the format of an inventory file?

A

ini file format

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

Define a group web with hosts toronto.example.com and vancouver.example.com

A

[web]

toronto. example.com
vancouver. example.com

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

I have 3 hosts running on the same 127.0.0.1 IP but different ports. My goal is to configure them. Explain why the following group configuration will not work?
And how to you resolve it?

[myservers]

  1. 0.0.1: 2000
  2. 0.0.1: 2001
  3. 0.0.1: 2002
A

Ansible inventory can associate only a single host with 127.0.0.1.
To resolve it use aliases

[myservers]
server1 ansible_host=127.0.0.1 ansible_port=2000
server2 ansible_host=127.0.0.1 ansible_port=2001
server3 ansible_host=127.0.0.1 ansible_port=2002

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

Define a group staging that contains two other groups: web and lb.

A

[staging:children]
lb
web

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

Define a group web that includes all servers web1.example.com to web20.example.com

A

[web]

web[1:20].example.com

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

Define two variables user and password for a group web

A

[web:vars]
user=macabo
password=eboubolo

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

What are possible types of a ansible variable?

A

Booleans, strings, dictionaries, lists

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

What are limitations of specifying variables in inventory files?

A

1) inventory files only support string and booleans as variable values
2) crowded inventory file

17
Q

How do you define variables to prevent shortcommings of defining them in inventory file?

A

Define them in YAML files located under folders group_vars or host_vars.

18
Q

what is the format of a file located under group_vars.

A

YAML

19
Q

What are possible parameters of a dynamic inventory script?

A
  • -host=hostname (for showing host details/variables of individual host)
  • -list (for listing groups)
20
Q

what is the aim of the –host parameter of an inventory script?

A

for showing host details/variables of individual host. Result is a json that shows variables and their values.

21
Q

what is the aim of the –list parameter of an inventory script?

A

returns all groups along with their hosts. result is a json object of group names to host list.

22
Q

How does Ansible retrieves variables for a speicific host, given –list returns list of groups?

A

–list includes an optimization that includes the meta section. meta is a json object of host to their variables.

23
Q

What measures are needed to use static and dynamic inventory files with a single playbook?

A

1) Put all files in the same folder
2) make the dynamic inventory file executables
3) Specify the folder location in ansible configuration file

24
Q

Write a fragment to configure inventory location in ansible config file

A

[defaults]

inventory = my_inventory

25
Q

When are dynamic inventory scripts invoked during the execution of a playbook? What is the implication?

A

Right before the playbook itself is invoked. the implication is that if the playbook cannot configure hosts that it spins up itsself.

26
Q

what is add_host used for?

A

add_hosts is used to add a host to an inventory dynamically during the execution of the playbook. It is different than dynamic inventory that generates all its hosts prior to the playbook being launched.

add_host can be used for instance to bring up a new vagrant machine and configure it within the same script.

27
Q

Does add_host modify the inventory file?

A

No. It only add to the runtime inventory and the change is not persisted to a file.

28
Q

explain group_by

A

Used to group nodes using some facts. For instance group by distribution. Can also be seen as a way to achieve conditional behaviour.

29
Q

How do you tell Ansible to ignore files with extension txt when loading dynamic inventories from a folder

A

add txt to the list of extensions to skip in ansible.cfg

inventory_ignore_extension

30
Q

What could be the use of empty groups in dynamic inventory file?

A

Empty group can be used to declare the group if the content is provided by a dynamic inventory script.

31
Q

Create ansible.cfg that sets the inventory location as /home/paoblo/ansible/ansible.cfg

A

[defaults]

inventory= /home/paoblo/ansible/ansible.cfg