Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ansible Training - Part 1 - Introduction

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. Agenda  Use Cases  How does Ansible Work? 

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

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

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

    Push Based  Built-in Modules  Simple
  5. 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
  6. 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
  7. 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
  8. 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>
  9. Test Connectivity to Servers  Ansible all –m ping –-ask-pass

     The output should look like this: Hostname | success >> { "changed": false, "ping": "pong" }
  10. 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
  11. 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.
  12. 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)
  13. 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