Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:ansible [2018/06/05 16:06] billdozor [Playbook/Role Creation] |
linux_wiki:ansible [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 41: | Line 41: | ||
* Each system administrator would then clone a copy of the repo into their home directory for local changes/ | * Each system administrator would then clone a copy of the repo into their home directory for local changes/ | ||
* Have an automated job sync the shared location every so often. | * Have an automated job sync the shared location every so often. | ||
- | * Example: Have cron perform a git pull for / | + | * Example: Have cron perform a git pull for /ansible/ every 30 mins. |
\\ | \\ | ||
Line 68: | Line 68: | ||
* Cron Job to execute inventory generation script: / | * Cron Job to execute inventory generation script: / | ||
- | * Example: Executes | + | * Example: Executes every 30 minutes. (*/30 * * * *) |
* Script that generates inventory files: / | * Script that generates inventory files: / | ||
Line 237: | Line 237: | ||
\\ | \\ | ||
**Playbooks map ansible groups to roles** | **Playbooks map ansible groups to roles** | ||
- | * Example playbook< | + | * Example playbook< |
# Description: | # Description: | ||
# Last Updated: 2018-04-08 | # Last Updated: 2018-04-08 | ||
Line 244: | Line 244: | ||
# hosts: group_name or ' | # hosts: group_name or ' | ||
- hosts: webservers_nginx | - hosts: webservers_nginx | ||
+ | |||
# roles: located in ../roles/ | # roles: located in ../roles/ | ||
roles: | roles: | ||
# role: role to assign to hosts, tags: tag(s) to give entire role | # role: role to assign to hosts, tags: tag(s) to give entire role | ||
- { role: webservers-nginx, | - { role: webservers-nginx, | ||
+ | |||
# Gather host facts for this playbook | # Gather host facts for this playbook | ||
gather_facts: | gather_facts: | ||
Line 255: | Line 257: | ||
* When a playbook is executed, all tasks in the assigned roles are run (unless only specific tasks/ | * When a playbook is executed, all tasks in the assigned roles are run (unless only specific tasks/ | ||
+ | \\ | ||
+ | **Gather a subset of facts** | ||
+ | |||
+ | If you do need to gather facts, consider gathering a subset of facts instead of everything in order to keep the fact collection fast. | ||
+ | * Example: Collect only the ansible_distribution facts< | ||
+ | gather_facts: | ||
+ | # Gather only ansible_distribution info (OS attributes) | ||
+ | gather_subset: | ||
+ | - ' | ||
+ | - ' | ||
+ | - ' | ||
+ | * Facts returned by the above subset< | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | * You can test your subset commands like this | ||
+ | * ad-hoc< | ||
+ | |||
+ | **Available Fact Subsets**: | ||
+ | * all | ||
+ | * min | ||
+ | * hardware | ||
+ | * network | ||
+ | * virtual | ||
+ | * ohai | ||
+ | * facter | ||
+ | |||
+ | \\ | ||
**See the Roles section** for what happens next. | **See the Roles section** for what happens next. | ||
Line 312: | Line 346: | ||
cp -R template-role/ | cp -R template-role/ | ||
- Modify the role's files as needed to create tasks, files, handlers, etc. | - Modify the role's files as needed to create tasks, files, handlers, etc. | ||
- | - FIXME -> Will upload | + | - Download zip archive of an {{ : |
- **New Playbook** | - **New Playbook** | ||
- Navigate to the playbooks directory< | - Navigate to the playbooks directory< | ||
- Copy your playbook template to a new playbook yaml file.< | - Copy your playbook template to a new playbook yaml file.< | ||
- | - Playbook Template< | + | - Playbook Template< |
# Description: | # Description: | ||
# Last Updated: 2018-03-15 | # Last Updated: 2018-03-15 | ||
Line 324: | Line 358: | ||
- hosts: | - hosts: | ||
- group_name_here | - group_name_here | ||
+ | |||
# roles: located in ../roles/ | # roles: located in ../roles/ | ||
roles: | roles: | ||
# role: role to assign to hosts, tags: tag(s) to give entire role | # role: role to assign to hosts, tags: tag(s) to give entire role | ||
- { role: role-name, tags: tag-name } | - { role: role-name, tags: tag-name } | ||
+ | |||
# Do not gather host facts for this playbook (comment out/remove if you need facts) | # Do not gather host facts for this playbook (comment out/remove if you need facts) | ||
gather_facts: | gather_facts: | ||
</ | </ | ||
- | - Edit the new playbook<code bash>vim ansible/ | + | - Edit the new playbook |
- hosts: my_ansible_group | - hosts: my_ansible_group | ||
roles: | roles: |