Roles Flashcards
What is the list of files and folders pertaining to a role called database?
database/defaults/main.yml /database/vars/main.yml /database/handlers/main.yml /database/files /database/templates /database/tasks/main.yml /database/meta/main.yml
How do I change the location of systemwide roles?
In ansible.cfg, change the defaulst.
[defaults]
roles_path=~/ansible/system_roles
This can also be done by setting env variable ANSIBLE_ROLES_APTH
Do ansible have a notion of importing or including other playbooks?
Yes. Use include to include tasks and plays.
include: django.yml
A variable proxy_hostname is defined in role database. I sit visible in a different role web?
Yes. Ansible has no notion of namespace across roles. A variable defined in one role will be visible everywhere else.
What is the difference between tasks in a playbook and tasks in a role?
In a role, default location for files is /rolename/files or /rolename/templates for templates.
In a normal playbook the default location is inventory location.
This has an impact on copy and template modules.
What is ansible-galaxy?
A command line tool that is used to find and download roles published by the community.
It can also be used to generate the skeleton for creating a role.
How do use galaxy to create a role scaffolding?
ansible-galaxy init -p playbooks/roles web
How do you declare role dependency?
dependencies:
- { role: ntp, ntp_server=ntp.ubuntu.com}
- { role: memcached}
- { role: activemq}
What is Ansible Galaxy?
An open source repo of community contributed ansible roles.
Install ntp role bennojoy from galaxy
ansible-galaxy install -p ./roles bennojoy.ntp
Where does ansible galaxy install roles by default?
In system wide roles location
List installed roles with galaxy
ansible-galaxy list
Uninstall a role with galaxy
ansible-galaxy remove bennojoy.ntp
How do you change the way ansible detect if a task has changed a state or failed?
use change_when and failed_when
What is ansible behavior when a task failed and how do you change this behavior?
- Ansible stops the processing when a task failed
- To change this behavior use failed_when: False
Explain following task:
- copy: src=/src/main/java/Job.java /src/main/java/Job.java failed_when: False register: result debug: var=result fail:
- Attempt to copy file Job1.java into Job.java
- If the task fails, do not stop
- register the result in the variable called result
- log the result
- stop the playbook execution
Ansible ad-hoc command to delete a prostgres db called players
- ansible –become –become-user postgres -m postgresql_db -a “name=players state=absent”
Where can I use filters in Ansible?
Inside {{}} and inside templates
What is the similitude between filters and pipes?
Using filters resembles using linux pipes. A variable is pipled through a filter.
Give an example of default filter and explain
“HOST”: “{{ database_host | default(‘localhost’) }}”
Expression evaluates to database_host if it is defined; otherwise it evaluates to ‘localhost’.
Examples of variable filters
failed, changed, success, skipped
Examples of file filters
basename, dirname, expanduser, realpath