linux_wiki:ansible

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:ansible [2018/06/05 16:03]
billdozor [Playbook Commands: Aliases]
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/testing before committing working modifications to the repo.   * Each system administrator would then clone a copy of the repo into their home directory for local changes/testing before committing working modifications to the repo.
   * 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 /ansible/ at the top of every hour.+    * Example: Have cron perform a git pull for /ansible/ every 30 mins.
  
 \\ \\
Line 68: Line 68:
  
   * Cron Job to execute inventory generation script: /etc/cron.d/ansible-generate-inventory   * Cron Job to execute inventory generation script: /etc/cron.d/ansible-generate-inventory
-    * Example: Executes at the bottom of every hour. (30 *)+    * Example: Executes every 30 minutes. (*/30 * * * *)
  
   * Script that generates inventory files: /ansible/scripts/inventory-file-gen.py   * Script that generates inventory files: /ansible/scripts/inventory-file-gen.py
Line 237: Line 237:
 \\ \\
 **Playbooks map ansible groups to roles** **Playbooks map ansible groups to roles**
-  * Example playbook<code bash># File: webservers_nginx.yml+  * Example playbook<code yaml># File: webservers_nginx.yml
 # Description: Nginx Webservers # Description: Nginx Webservers
 # Last Updated: 2018-04-08 # Last Updated: 2018-04-08
Line 244: Line 244:
 # hosts: group_name or 'all' # hosts: group_name or 'all'
 - 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, tags: webservers-nginx }     - { role: webservers-nginx, tags: webservers-nginx }
 +
   # Gather host facts for this playbook   # Gather host facts for this playbook
   gather_facts: yes</code>   gather_facts: yes</code>
Line 255: Line 257:
   * When a playbook is executed, all tasks in the assigned roles are run (unless only specific tasks/actions are selected using tags and/or limits).   * When a playbook is executed, all tasks in the assigned roles are run (unless only specific tasks/actions are selected using tags and/or limits).
  
 +\\
 +**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<code yaml># Gather host facts for this playbook
 +  gather_facts: yes
 +  # Gather only ansible_distribution info (OS attributes)
 +  gather_subset:
 +    - '!all'
 +    - '!min'
 +    - 'distribution'</code>
 +    * Facts returned by the above subset<code bash>"ansible_distribution": "CentOS",
 +        "ansible_distribution_file_parsed": true,
 +        "ansible_distribution_file_path": "/etc/redhat-release",
 +        "ansible_distribution_file_variety": "RedHat",
 +        "ansible_distribution_major_version": "7",
 +        "ansible_distribution_release": "Core",
 +        "ansible_distribution_version": "7.5.1804",
 +        "ansible_os_family": "RedHat",</code>
 +  * You can test your subset commands like this
 +    * ad-hoc<code bash>ansible -m setup -a 'gather_subset=!all,!min,distribution' localhost</code>
 +
 +**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/ my-new-role</code> cp -R template-role/ my-new-role</code>
     - 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 an example role-template archive file for download from this page.+      - Download zip archive of an {{ :linux_wiki:role-template.zip |example role template}}.
   - **New Playbook**   - **New Playbook**
     - Navigate to the playbooks directory<code bash>cd ${HOME}/repos/ansible/playbooks/</code>     - Navigate to the playbooks directory<code bash>cd ${HOME}/repos/ansible/playbooks/</code>
-    - Copy your playbook template to a new playbook yaml file.<code bash>cp template_playbook.yml my_new_playbook.yml</code> +    - Copy your playbook template to a new playbook yaml file.<code bash>cp TEMPLATE_PLAYBOOK.yml my_new_playbook.yml</code> 
-      - FIXME -Will upload an example playbook template file for download from this page. +      - Playbook Template<code yaml TEMPLATE_PLAYBOOK.yml># File: TEMPLATE_PLAYBOOK.yml 
-    - Edit the new playbook<code bash>vim ansible/playbooks/my_new_playbook.yml+# Description: PLAYBOOK DESCRIPTION HERE 
 +# Last Updated: 2018-03-15 
 +# Recent Changes:-Initial release 
 + 
 +# hosts: group_name or 'all' 
 +- hosts: 
 +    - group_name_here 
 + 
 +  # roles: located in ../roles/ 
 +  roles: 
 +    # role: role to assign to hosts, tags: tag(s) to give entire role 
 +    - { role: role-name, tags: tag-name } 
 + 
 +  # Do not gather host facts for this playbook (comment out/remove if you need facts) 
 +  gather_facts: no 
 +</code> 
 +    - Edit the new playbook (vim ansible/playbooks/my_new_playbook.yml)<code yaml>
 - hosts: my_ansible_group - hosts: my_ansible_group
   roles:   roles:
  • linux_wiki/ansible.1528229018.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)