---------------------------------------------------------------
#
# Slides :
http://slides.unsupported.io/ansible-b2b-slides/
# Alex Juarez @mralexjuarez
# 09:05 AM Irving Convention Center May 31, 2019
#
---------------------------------------------------------------
(b2b is beginner to brilliant)
1. Why ?
2. Vocabulary Lesson
3. Environment Setup
4. Case Studies
Why
=====
Ansible is an agentless configuration management tool to automate configuration. It makes it easier to have consistency.
Process docs rely on humans and they are not good at doing the same thing the same way over and over.
Vocabulary
=====
Idempotence - Idempotence means that running the same command several times produces the same result as running it only once.
https://peterlyons.com/problog/2010/05/on-idempotence-intention-and-unix-commands/
Playbooks - Collection of plays
Role - Collection of plays "The concept of an Ansible role is simple; it is a group of variables, tasks, files, and handlers that are stored in a standardized file structure."#s://linuxacademy.com/blog/red-hat/ansible-roles-explained/
Plays - A mapping of a task 'Playbook is a mapping between hosts and roles.'
https://stackoverflow.com/questions/32101001/ansible-playbooks-vs-roles#32101316
Task - The reason for the playbook. Combined action with name and arguments
Action - Module + arguments ( actual program )
Module - The work being kicked off. ex: The hostname module is kicked off on the machine to change the hostname.
Handler - Special case of task that are only called when something happens
Templates - Config files that can have variables in them
Files - Are static files in a playbook that are consumed by ansible somehow
Ansible galaxy - Repository of premade roles but they look like playbooks?
Glossary ->
https://docs.ansible.com/ansible/latest/reference_appendices/glossary.html
Environment
======
Install Virtualbox
Install Vagrant
Clone or download the Ansible Examples Repo -
https://github.com/mralexjuarez/ansible-b2b
On Boarding Program Case
======
Setup machines
break it
then fix it
Demo Time
=====
ansible -i hosts_file -m setup localhost
comm -i = inventory hosts_file is a file of hosts to target and then module is setup and localhost is the target. Is setup as an INI format
the beginning of a YAML file is --- and the closing line is ...
Lists are defined with - element one per line
dictionary / key value are like this
car:
make: Nissian
model: Juke
color: Falu
YAML Linter is
http://www.yamllint.com/
Directory Structure One-Liner
https://gist.github.com/mralexjuarez/c4cfae2f6f4f23af1d1b
Best Practices :
https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html#directory-layout
become: true - Become root override default of false. This allows to use sudo
Ansible uses SSH keys to talk
Molecule is the testing suite for ansible
https://molecule.readthedocs.io/en/stable/
Ansible Facts will spit out all the debug information
Variables are encased in {{ var }}
can use dot notation or ['array'] style
CentOS doesn't like Virtualbox so cannot follow along :(
Variable Precedence
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
Debug Module
Variables in Precedence
Files
You can create a backup prior to changing a file.
Templates in Ansible are Jinja2 templates or .j2 files
https://www.fullstackpython.com/jinja2.html
Appending a line
lineinfile is a module for adding a single line at the end
if you include the option insertafter you can define where to insert
Playbook 4 - Conditionals and Errors
=====
Default is to fail on error / non-zero output
Registering a variable
Is Apache running?
#task name freeform
- name user string
#shell module to run shell command
shell: "shell command"
#define a local variable to get command results
register: variable_name
changed_when: Falsse
ignore_errors: True
become: True
#talk is based on palybooks that are not published but are local to speaker's docs
nsible
Ansible has several built ins based on the
ignore errors to ignore errors and then rc to get response code
Tower is the 10k / year or 14k / year paid web internface
AWX is the Community Edition from Red Hat
Rundeck is another option
awx.rackersupport.com/#/home