Ansible: Up and Running (1st/2nd edition) by Lorin Hochstein

Ansible:

The 1st edition of the book not only covers less topics but it felt outdated as there were many updates over the years for Ansible. 2nd edition luckily only improves on a good base of the book bringing (alomst) latest development, and now (2nd edition) feels like a great start to pick up this wonderful tool.

Intro:

[defaults]
hostfile = inventory.yaml
host_key_checking = False
- name: Configure nginx
  hosts: docker
  sudo: True                              # JSON formatting is different
  tasks:
    - name: install nginx
      apt: name=nginx                     # [OR]
      shell: yum install -y nginx         # [OR]
      yum: state=present name=nginx       # [OR]
      service: state=started name=nginx
    - name: copy index.html
      template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html
mode=0644
- name: install nginx
  apt: >
      name=nginx
      update_cache=yes
tasks:
  - name: update nginx config
    file: [...]
    notify: nginx restart
handlers:
  - name: nginx restart
    service: name=nginx state=restarted
server {
    [...]
    server_name ;
[prod]
server-http.example
server-https1.example zone=blue
server-https[2-6].example zone=red

[test]
virtual85

[all:vars]
ntp_host=time.us.world

[prod:vars]
db_user=packet
db_port=1521

Variables

Facts

Playbooks

- name: install nginx and libpq-dev
  apt:
      name: ""
      state: present
      update_cache: yes
  become: true
  with_items:
      - libpq-dev
      - nginx
- include: Redhat.yml
when: ansible_os_family == 'Redhat'
- include: Debian.yml
when: ansible_os_family == 'Debian'

Custom modules

we can create custom Python modules - Ansible provides a starter project to help us with this task

Callback plugins

[defaults]
callback_whitelist = mail, slack, junit, jabber, hipchat, logstash, ...

Speeding up Ansible

roles/django/meta/main.yaml
dependencies:
    - { role: web }
    - { role: memcached }

Galaxy:

Vault:

--- group_vars
  \--- <environment>
     \--> vault     # all variables start w/ vault_
     \--> vars      # define variables as test_variable: ""

Jinja2 templating:

Vagrant

a quick intro into using Vagrant with Ansible

AWS:

debugging

Docker:

Windows

tasks:
    - name: install software security updates
      win_updates:
        category_names:
          - SecurityUpdates
          - CriticalUpdates
      register: update_result

Others