Table of Contents

Ansible Playbook Downloads

General Information

This page will contain Ansible playbook/role downloads.


In order to install/configure Ansible, see this page first.

Checklist


Playbook Downloads

Example Ansible playbooks/roles are maintained here: https://gitlab.com/whowe/ansible


Playbook Snippets

Snippets of tasks to provide examples of some Ansible modules in action.

Most of these snippets are tasks that span multiple documentation sources or were discovered through searches and trial/error.


Ansible Module Index: https://docs.ansible.com/ansible/2.4/modules_by_category.html


ACLs

ACL module.

Examples


Copy Module

Copy module examples.

Examples


File Module

Some file module examples.

Examples


Pre Req Tests

Using a combination of the command module, registering variables, and the fail module, any command can be checked for a certain return code.

This can be useful for pre-req checks.

Examples


Python: Install Pip

One method of installing pip into a Python environment.

# Check to see if pip exists, store answer in "pip_path"
- name: software|Check for pip
  stat:
    path: "/usr/bin/pip"
  register: pip_path
 
# Copy pip script to system if pip did not exist
- name: software|No Pip - Copy get-pip.py for pip install
  copy:
    src: "python_get-pip.py"
    dest: "/root/get-pip.py"
  when: pip_path.stat.exists == False
 
# Install pip into Python site packages if pip did not exist
- name: software|No Pip - Install pip using Python (/usr/bin/python)
  command: "/usr/bin/python /root/get-pip.py"
  when: pip_path.stat.exists == False
 
# Remove get-pip.py if pip did not exist before
- name: software|No Pip - Remove get-pip.py
  file:
    path: "/root/get-pip.py"
    state: absent
  when: pip_path.stat.exists == False

Python: Install Packages

Installing Python packages via pip.


Remote Scripts

Running remote scripts and capturing results.

Examples


SSH Keys

Manipulating SSH keys on remote hosts.

Examples


Unarchive

Copying tarballs to a remote system only if newer and un-archiving only if the tarball changed.

# Copy myapp tarball if source is newer
- name: my_app|MyApp tarball copy
  copy:
    src: "myapp_current.tar"
    dest: "/var/opt/myapp/"
    owner: root
    group: root
    mode: 0755
    follow: yes
  register: myapp_new_archive
 
# Unarchive tarball on remote system if it was changed
- name: my_app|MyApp tarball unarchive if newer
  unarchive:
    src: "/var/opt/myapp/myapp_current.tar"
    dest: "/var/opt/myapp/"
    copy: no
  when:
    - myapp_new_archive is changed

User

The user module.

Examples


When Conditional

Only execute certain tasks under certain conditions.

Examples


Yum Repository

Adding a yum repo with the yum_repository module.

Examples