La Automatización permite construir ambientes idénticos una vez tras otras. Todos los paquetes necesarios, archivos de configuración, etc. se pueden definir de forma lógica y usarlos para construir plataformas de forma automática y libre de errores.
Es una herramienta que nos permite gestionar configuraciones, aprovisionamiento de recursos, despliegue automático de aplicaciones y muchas otras tareas de TI de una forma limpia y sencilla.
Existen RPM's disponibles para EPEL 6 y 7
1 $ sudo yum install ansible
1 $ sudo apt-get install software-properties-common
2 $ sudo apt-add-repository ppa:ansible/ansible
3 $ sudo apt-get update
4 $ sudo apt-get install ansible
1 $ sudo apt-get update
2 $ sudo apt-get install python-pip python-dev git -y
3 $ sudo pip install PyYAML jinja2 paramiko
4 $ git clone https://github.com/ansible/ansible.git
5 $ cd ansible
6 $ sudo make install
7 $ sudo mkdir /etc/ansible
8 $ sudo cp ~/ansible/examples/hosts /etc/ansible/
1 $ brew update
2 $ brew install ansible
1 $ sudo pip install ansible
1 $ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.101.104
1 ├── hosts <- inventory
2 ├── playbook.yml <-playbook
3 └── roles
4 └── webserver <- role webserver
5 ├── files
6 │ └── main.go
7 └── tasks
8 └── main.yml <- fichero de tareas
1 1.web.sandbox.sophimania.pe ansible_ssh_host=192.168.20.80 ansible_ssh_port=22
2 1.lb.sandbox.sophimania.pe ansible_ssh_host=192.168.20.81 ansible_ssh_port=22
3 1.db.master.sandbox.sophimania.pe ansible_ssh_host=192.168.20.82 ansible_ssh_port=22
1 [webservers]
2 [1:1].web.sandbox.sophimania.pe
3
4 [lbservers]
5 1.lb.sandbox.sophimania.pe
6
7 [dbservers:children]
8 dbservers.masters
9 dbservers.slaves
1 - name: Install Nginx Web Server
2 apt: pkg=nginx state=latest
1 - name: Install common package dependencies
2 apt:
3 name: "{{ item }}"
4 state: present
5 register: install_common_package_dependencies
6 when: common_package_dependencies is defined
7 with_items: common_package_dependencies
8 tags:
9 - apt
10 - dependencies
1 - name: Common stuff for all the server
2 hosts: all
3 sudo: yes
4 gather_facts: yes
5 roles:
6 - common
7 tags:
8 - all
9 - common
10
11 - name: Install MySQL
12 hosts: dbservers
13 gather_facts: yes
14 sudo: yes
15 roles:
16 # - { role: contrib/geerlingguy.mysql, when: "user == 'vagrant'" }
17 - contrib/geerlingguy.mysql
18 - postgresql
19 tags:
20 - install
21 - mysql
22 - databases
1 user: vagrant
2
3 app_name: "sophimania"
4 app_db_name: "sophimania"
5 app_dir_home: "/home/{{ user }}"
6 apps_path: "{{ app_dir_home }}/{{ repository_name }}"
7 app_dir: "{{ apps_path }}/{{ app_name }}"
8 dir_logs_supervisor: "/var/log/supervisor"
1 ├── README.md
2 ├── defaults
3 │  └── main.yml
4 ├── handlers
5 │  └── main.yml
6 ├── meta
7 │  └── main.yml
8 ├── tasks
9 │  ├── configure.yml
10 └── templates
11 ├── environment.j2
1 ansible-galaxy install username.rolename
1 ansible-galaxy install -r requirements.yml -p provision/ansible/roles
1 # Install a role from the Ansible Galaxy
2 - src: dgnest.authorization
3 - src: dgnest.common
4 - src: hadenlabs.nginx
5 - src: dgnest.supervisor
6 - src: dgnest.postgresql
7
8 # Install a role from GitHub
9
10 # - name: hadenlabs.superslacker
11 # src: https://github.com/hadenlabs/ansible-role-superslacker
12 # version: origin/master
1 - name: webservers
2
3 pre_tasks:
4 - shell: echo 'o/'
5
6 roles:
7 -{ role: some_role }
8
9 tasks:
10 - shell: echo 'still busy'
11
12 post_tasks:
13 - shell: echo 'Good Bye'