$30 off During Our Annual Pro Sale. View Details »

Ansible Training - Part 1 - Introduction

lvandeyar
April 22, 2015

Ansible Training - Part 1 - Introduction

Talk I gave to my coworkers to kick off Ansible Development.

lvandeyar

April 22, 2015
Tweet

More Decks by lvandeyar

Other Decks in Technology

Transcript

  1. Ansible Training – Part 1 - Introduction Laurence Vandeyar, Senior

    Systems Engineer April 30th, 2015
  2. Agenda  Use Cases  How does Ansible Work? 

    Ansible Benefits  Installing Ansible  First Playbook  Windows Support  Cisco Support
  3. Use Cases  Configuration Management  Desired State  Deployment

     Application Deployment  Orchestration  Failover  Provisioning  Build Environment
  4. How does Ansible Work?  Playbook – Series of Tasks

     Install Apache  Copy custom index.html
  5. Ansible Benefits  Playbook Language  YAML  Agentless 

    Push Based  Built-in Modules  Simple
  6. 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
  7. 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
  8. Inventory File  Nano /ansible-playbooks/webserver/inventory  Contents: [all] hostname ansible_ssh_port=22

    ansible_ssh_user=scelluser
  9. 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
  10. Webserver.yml  Nano /ansible-playbooks/webserver/ansible.cfg  Contents: [defaults] hostfile=inventory

  11. Index.html  Nano /ansible-playbooks/webserver/files/index.html  Contents: <html> <head> <title>TradeStation</title> </head>

    <body> <h1>Deployed by Ansible</h1> <p><b>Pat yourself on the back!</b>You just wrote your first Ansible playbook. </body></p> </html>
  12. Test Connectivity to Servers  Ansible all –m ping –-ask-pass

     The output should look like this: Hostname | success >> { "changed": false, "ping": "pong" }
  13. 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
  14. 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.
  15. 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)
  16. 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
  17. Cisco Support  Cisco Module: https://github.com/networklore/ansible-cisco-snmp

  18. The End!!