Share
Embed
Ansible Training - Part 1 - Introduction
Talk I gave to my coworkers to kick off Ansible Development.
lvandeyar
April 22, 2015
Transcript
18 slides
-
Ansible Training – Part 1 - Introduction Laurence Vandeyar, Senior
Systems Engineer April 30th, 2015 -
Agenda Use Cases How does Ansible Work?
Ansible Benefits Installing Ansible First Playbook Windows Support Cisco Support -
Use Cases Configuration Management Desired State Deployment
Application Deployment Orchestration Failover Provisioning Build Environment -
How does Ansible Work? Playbook – Series of Tasks
Install Apache Copy custom index.html -
Ansible Benefits Playbook Language YAML Agentless
Push Based Built-in Modules Simple -
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 -
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 -
Inventory File Nano /ansible-playbooks/webserver/inventory Contents: [all] hostname ansible_ssh_port=22
ansible_ssh_user=scelluser -
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 -
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> -
Test Connectivity to Servers Ansible all –m ping –-ask-pass
The output should look like this: Hostname | success >> { "changed": false, "ping": "pong" } -
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 -
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. -
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) -
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