introduction to ansible
TRANSCRIPT
Introduction To Ansible
Kasun Madura Rathnayaka.Senior Sys/Devops Engineer
BSc (Hons) Electrical and Information, Engineering AWS Certified Solutions Architect Associate AMIE(SL),CCIP,RHCE,RHCSA,[email protected] skype:kasunmadura141
Continuous Integration
Teams integrate their work multiple times per day.
Each integration is verified by an automated build
Significantly reduces integration problems
Develop cohesive software more rapidly
Source: Martin Fowler
Continuous Integration
Continuous Integration and Automation Tools
●CI Tools
○ Jenkins ,Teamcity ,Buildbot, Bamboo
●Automation Tools
○ Puppet,Chef,Ansible
●Version Control
○ svn,git,perforce
●Build Tool
○ Maven,ant,grant
● Code quality inspection tool
○ Sonar,Sonarqube
Ansible
What is Anible ?
Why we need Ansible ?
Advantage and Disadvantages..
Compare with Puppet and Chef
What is Ansible
● “radically simple IT automation platform”
●Describe the intended system state using playbooks written in YAML
●Requires no agent on the managed machine, only a Python interpreter and an
SSH server
Shell Script● #!/bin/bash
● echo "fs.file-max=20000" | sudo tee -a /etc/sysclt.conf
● sudo apt-get -y install build-essential
● sudo mkdir -p /var/www/kasun
● sudo apt-get -y install apache2
● sudo a2enmod rewrite
● sudo tee /etc/apache2/sites-available/mysite <<ENDOFFILE
● <VirtualHost *:80>
● DocumentRoot "/var/www/kasun/"
● ServerName www.kasun.com
● # Other directives here
● </VirtualHost>
● ENDOFFILE
Ad-hoc configurationConfiguration file /etc/ansible/ansible.cfg
1st ansible command :)
$ cat >hosts [webservers] 192.168.1.40 ^D
$ ansible -vvv all -i hosts -u root -m ping
$ ansible -vvv webserver -i hosts -u root -m apt -a 'name=cowsay state=present'
$ ssh 192.169.1.40 cowsay moo
Playbooks
Consolidate tasks and configuration knobs into a single YAML file
Support templating—both in playbooks and in file templates—by way of Jinja2
Can be one file, or split up into many roles (more later!)
Running a playbook
• ansible-playbook playbook.yml
• -i to specify a local inventory file (e.g. hosts)
• -k if you have to enter a password for this run
• Use authorized_key to install an SSH key for future runs
Real Example
Get the ball rolling :)
Discussion
Quiz