Inventory and configuration files Flashcards

1
Q

Default inventory location

A

Default: /etc/ansible/hosts
Specified by cli: ansible -i
Can be set in ansible.cfg

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

Static vs Dynamic

A

Static:
-ini or yaml
- esy to manage for static config
Dynamic:
-executable (bash, python script etc
-script returns json containing inventory information
-good for use with cloud resources when sudden changes

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

Vars

A

Ansible recommends that vars not to be defined in inventory files:

  • should be stored in yaml files located relative to inventory file
  • group_vars dir
  • host_vars dir
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Conf files which are typically used for each project

A
ansible.cfg in project dir:
[defaults]
inventory = hosts.yaml
remote_user = ansible
host_key_checking = false
forks = 5
[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Setup ansible user to be not asked for password while sudo

A

sudo visudo to update /etc/sudoers file

ansible ALL=(ALL) NOPASSWD:ALL

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

Typical yaml static inventory

A
---
all:
hosts:
  children:
    media:
      hosts:
        media1:
        media2:
    webservers:
      hosts:
         10.0.1.1:
         10.0.1.2:

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

Show which conf file will be used

A

ansible –version

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

Show list of hosts

A

ansible all -i inventory/hosts.yaml –list-hosts

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

Create custom facts in facts.d dir

A
mkdir -p /etc/ansible/facts.d on a slave node- node1
vim /etc/ansible/facs.d/pref.fact
[server]
software=adobe
[params]
adobe_v=1.7.1

on a control node run:
ansible node1 -m setup -a “filter=ansible_local”

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

Possible location of conf files

A

ANSIBLE_CONFIG (conf variable)
ansible.cfg (current dir)
~/.ansible.cfg (in home dir)
/etc/ansible/ansible.cfg

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

ansible-config options

A
  1. ansible-config list -Print config options
  2. ansible-config dump -dumps config
  3. ansible-config view -view config file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Useful params in ansible.cfg

A
[defaults]
inventory=inventory
roles_path=/home/ansible/.ansible/roles
forks = 10
remote_user = ansible
host_key_checking = False
log_path = /my/project/ansible-errors.log

[priviledge_escalation]
become = yes
become_method = sudo
become_user = root

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