+ All Categories
Home > Software > Ansible Hands On

Ansible Hands On

Date post: 15-Apr-2017
Category:
Upload: gianluca-farinelli
View: 310 times
Download: 0 times
Share this document with a friend
17
Anxious about DevOps management & deploy ? DevOps made simple. @baiolo
Transcript
Page 1: Ansible Hands On

Anxious about DevOpsmanagement & deploy ?

DevOps made simple.@baiolo

Page 2: Ansible Hands On

http://www.ansible.com/homeFrom the main website:

“Deploy apps.Manage systems. Crush complexity.

Ansible is a powerful automation tool that you can learn quickly.”

Page 3: Ansible Hands On

https://github.com/ansible/ansible“Ansible is a radically simple IT automation

platform ... Avoid writing scripts or custom code ... automate in a language that

approaches plain English, using SSH, with no agents to install on remote systems.”

The Octocat says:

Page 4: Ansible Hands On

Some design principles:Manage machines very quickly and in parallel.Avoid custom-agents and additional open ports, be agentless by

leveraging the existing SSH daemon.Describe infrastructure in a language that is both machine and

human friendly.Manage new remote machines instantly, without bootstrapping

any software.Allow module development in any dynamic language.

Page 5: Ansible Hands On

Ok, so it seems so damn’ c00l ! Install !$ git clone git://github.com/ansible/ansible.git --recursive$ cd ./ansible$ source ./hacking/env-setup

You can use the dev release to get latest features & bugfix.Root permissions are not required.No daemons or database setup are required.

Install, take two:$ sudo aptitude install ansible

Page 6: Ansible Hands On

And then let’s roll:Create /etc/ansible/hosts and put one or more remote systems in it.Your public SSH key should be located in authorized_keys on those systems.[aruba]ext-ubudb01ext-ubudb02ext-ubudemo01ext-debweb01

Page 7: Ansible Hands On

Inventory[webservers]foo.example.combar.example.com

[dbservers]one.example.comtwo.example.comthree.example.com

Page 8: Ansible Hands On

Inventory… a bit more[webservers]www[01:50].example.com

[databases]db-[a:f].example.com

Page 9: Ansible Hands On

My first ansible command:$ ansible all -m ping -u root

Answer:...ext-ubudb01 | FAILED => SSH encountered an unknown error...ext-ubudb02 | success >> {

"changed": false,"ping": "pong"

}...

Page 10: Ansible Hands On

My second ansible command:$ ansible all -a "/bin/echo hello"

Answer:...ext-ubudb02 | success | rc=0 >>hello

ext-ubudemo01 | success | rc=0 >>hello...

Page 11: Ansible Hands On

Modules:ansible webservers -m service -a "name=httpd state=started"ansible webservers -m pingansible webservers -m command -a "/sbin/reboot -t now"

Page 13: Ansible Hands On

Modules… some file modules:acl - Sets and retrieves file ACL information.assemble - Assembles a configuration file from fragmentscopy - Copies files to remote locations.fetch - Fetches a file from remote nodesfile - Sets attributes of filesfind - return a list of files based on specific criteria...

Page 14: Ansible Hands On

Last piece: PlayBooksPlaybooks are Ansible’s configuration, deployment, and orchestration language.They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process.

Page 15: Ansible Hands On

Last piece: PlayBooksgithub.com/ansible/ansible-examples/blob/master/lamp_simple/site.yml# This playbook deploys the whole application stack in this site.- name: apply common configuration to all nodes

hosts: allremote_user: rootroles:- common- name: configure and deploy the webservers and application code

hosts: webserversremote_user: rootroles:- web- name: deploy MySQL and configure the databaseshosts: dbserversremote_user: rootroles:- db

Page 16: Ansible Hands On

Last piece: PlayBooks### Example Ansible playbook that uses the MySQL module.#- hosts: all

user: roottasks:

- name: Create database usermysql_user: user=bob password=12345 priv=*.*:ALL state=present

- name: Create databasemysql_db: db=bobdata state=present

- name: Ensure no user named 'sally' exists and delete if found.mysql_user: user=sally state=absent

Page 17: Ansible Hands On

That’s All !and don’t be

anxious !


Recommended