Slide 1

Slide 1 text

Ansible Training – Part 1 - Introduction Laurence Vandeyar, Senior Systems Engineer April 30th, 2015

Slide 2

Slide 2 text

Agenda  Use Cases  How does Ansible Work?  Ansible Benefits  Installing Ansible  First Playbook  Windows Support  Cisco Support

Slide 3

Slide 3 text

Use Cases  Configuration Management  Desired State  Deployment  Application Deployment  Orchestration  Failover  Provisioning  Build Environment

Slide 4

Slide 4 text

How does Ansible Work?  Playbook – Series of Tasks  Install Apache  Copy custom index.html

Slide 5

Slide 5 text

Ansible Benefits  Playbook Language  YAML  Agentless  Push Based  Built-in Modules  Simple

Slide 6

Slide 6 text

Installing Ansible $ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install ansible

Slide 7

Slide 7 text

First Playbook  Files created for this Playbook  /ansible-playbooks/webserver/inventory  /ansible-playbooks/webserver/ansible.cfg  /ansible-playbooks/webserver/webserver.yml  /ansible-playbooks/webserver/files/index.html  Prep Environment  SSH to Ansible Server  Sudo -s  Mkdir /ansible-playbooks/  Mkdir /ansible-playbooks/webserver/  Mkdir /ansible-playbooks/webserver/files

Slide 8

Slide 8 text

Inventory File  Nano /ansible-playbooks/webserver/inventory  Contents: [all] hostname ansible_ssh_port=22 ansible_ssh_user=scelluser

Slide 9

Slide 9 text

Config File  Nano /ansible-playbooks/webserver/webserver.yml  Contents: --- - name: Install Webserver hosts: all sudo: yes tasks: - name: Install Apache apt: name=apache2 state=present - name: Deploy Custom Homepage template: src=files/index.html dest=/var/www/html

Slide 10

Slide 10 text

Webserver.yml  Nano /ansible-playbooks/webserver/ansible.cfg  Contents: [defaults] hostfile=inventory

Slide 11

Slide 11 text

Index.html  Nano /ansible-playbooks/webserver/files/index.html  Contents: TradeStation

Deployed by Ansible

Pat yourself on the back!You just wrote your first Ansible playbook.

Slide 12

Slide 12 text

Test Connectivity to Servers  Ansible all –m ping –-ask-pass  The output should look like this: Hostname | success >> { "changed": false, "ping": "pong" }

Slide 13

Slide 13 text

Running the Playbook  Ansible-playbook webserver.yml –K –-ask-pass  The output should look like this: PLAY [Install Webserver] ****************************************************** GATHERING FACTS *************************************************************** ok: [172.26.97.79] TASK: [Install Apache] ******************************************************** changed: [172.26.97.79] TASK: [Deploy Custom Homepage] ************************************************ changed: [172.26.97.79] PLAY RECAP ******************************************************************** 172.26.97.79 : ok=3 changed=2 unreachable=0 failed=0

Slide 14

Slide 14 text

Breakdown of Playbook  Name: A comment that describes the playbook or play. Ansible will write this to STDOUT when the playbook/play runs.  Sudo: If set to yes/true Ansible will the playbook will run as root after ssh login  Tasks: Tasks can also be referred to as plays. Every task must contain a key with the name of a module and a value for with arguments to that module. In our example we used the APT module with a name of a package and a state. We also contained the Template module with the name of the template file and src and dest.  Modules: Ansible ships with a number of modules. Users can also write their own modules.

Slide 15

Slide 15 text

Windows Support Ansible supports Windows from a linux control machine. To get the linux machine ready to communicate with windows, do the following:  Apt-get install libkrb5-dev  wget https://bootstrap.pypa.io/get-pip.py  python get-pip.py  Reboot now  pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm  pip install Kerberos (Only install when communicating with servers on a domain)

Slide 16

Slide 16 text

Windows Module  Test Connectivity to Servers  ansible all -i inventory -m win_ping --ask-pass - name: Make Testr Dir hosts: all tasks: - name: Run Script to make dir script: files/script.ps1

Slide 17

Slide 17 text

Cisco Support  Cisco Module: https://github.com/networklore/ansible-cisco-snmp

Slide 18

Slide 18 text

The End!!