Variables and Facts Flashcards

1
Q

How do you define variables in playbook?

A

vars:
key_file: /usr/local/nginx.key
server_name: localohost

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

How do you define variables in playbook using a file?

A

vars_files:

- nginx.yml

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

How to log out the content of a variable?

A
  • debug: var=variable name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Put the result of executing a command in a variable

A
  • name: capture current user into a varianle
    command: whoami
    register: login
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you prevent ansible from stoping execution of a task after encountering an error?

A

Add the flag ignore_errors: True to the task definition.

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

What is the type of value received when using register clause?

A

dictionary. Though the list of fields depends on each module.

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

How do you know what are the fields of the dictionary returned by the register clause?

A

Log the result and review the fields. Official documentation of modules often does not include the list of fields.

  • name: log a registered variable
    command: whoami
    register: login
    debug: var=login
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Assume I use the register clause with the command module. The result populated by register is a dictionary. What field of this dictionary contains the true result of the command?

A

stdout

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

If a variable “user” contains a dictionary, how do you access a key password of this dictionary?

A

{{ user.password }}

{{ user[‘password’] }}

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

In what case can you use {{ user[‘name’] }} where you cannot use {{ user.name }}?

A

if the key of the dictionary contained in the variable ‘user’ has spaces. for instance {{ user[‘firstname and lastname’] }}

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

What are facts?

A

Information Ansible gathers on the remote machine before running the playbook.

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

Example of facts

A

CPU Architecture, Operating System, memory, disk info

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

What is the ad-hoc command for retrieving facts?

A

ansible server -m setup

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

What is the ad-hoc command for retrieving facts starting with ansible_eth?

A

ansible server -m setup -a “filter=ansible_eth*”

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

Explain this: {{ ansible_local.example.book.title }}

A

This returns a fact named title defined under the group named book in a file named example.fact located at /etc/ansible/facts.d on one of the managed hosts.

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

Explain local facts?

A

facts that are defined on a speicific machine by its owner or operator. This is different from standard facts such as memory and disk info that are collected by Ansible.

17
Q

How do you define local facts?

A

Define a file in ini format and store it under /etc/ansible/facts.d

18
Q

How do you display all tasks of a playbook?

A

ansible-playbook –list-tasks playbook.yml

19
Q

Can an ansible variable reference another variable?

A

Yes, definitely. Example:

venv_path: “{{ venv_home }}/{{ proj_name }}”

20
Q

What is the difference in the way the apt module and the pip modules handle list?

A

apt module will results in once single execution of apt with the list of packages passed as argument

pip will be called many times, once for each package in the list.

21
Q

We want to execute a task as root. what instruction do we use to facilitate this in the playbook?

A
  • name: example of task that escalate priviledges
    apt : pkg=nginx update_cache=yes
    become: True