Sergio Guillen Mantilla
@donkeysharp
whoami_
$
Presentando...
- block: - name: Update repositories apt: update_cache: yes cache_valid_time: 3600 - name: Install base packages apt: name: "{{item}}" with_items: - apt-transport-https - build-essential - git - vim - htop - lsof - dstat - strace - tmux
$ pip install ansible
$ sudo apt-get install ansible
$ sudo yum install ansible
$ git://github.com/ansible/ansible.git --recursive
Hagamos una analogía
El Punto de Ingreso
--- - hosts: web become: True vars_files: - group_vars/variables.yml pre_tasks: - debug: msg='Starting docker setup playbook' post_tasks: - debug: msg='Finished docker setup playbook' tasks: - name: Crear archivo plano file: path: /tmp/archivillo_2 state: touch mode: 0755 owner: ansible group: ansible - name: Crear un directorio file: path: /tmp/miDirectorio state: directory mode: 0700 owner: ansible group: ansible
playbook.yml
Las Entradas
[web] 107.170.35.179 107.170.35.123 107.170.34.214 [web:vars] ansible_user=ansible ansible_password=98765 ansible_become_password=98765 [load_balancer] 107.170.32.38 [load_balancer:vars] ansible_user=ansible ansible_password=123456 ansible_become_password=123456
inventory.yml
Las Instrucciones
- digital_ocean: state: present command: droplet id: 123 name: mydroplet api_token: XXX size_id: 2gb region_id: ams2 image_id: fedora-19-x64 wait_timeout: 500
- name: restart service systemd: state: restarted daemon_reload: yes name: crond
- name: Mount DVD read-only mount: path: /mnt/dvd src: /dev/sr0 fstype: iso9660 opts: ro state: present
- user: name: james shell: /bin/bash groups: admins,developers append: yes
- copy: src: /srv/myfiles/foo.conf dest: /etc/foo.conf owner: foo group: foo mode: "u=rw,g=r,o=r"
- name: Install base packages apt: name: "{{item}}" with_items: - apt-transport-https - build-essential - git - vim
- name: LB config file template: src: templates/config.tpl dest: /etc/nginx/sites-available/default mode: "u=rw,g=r,o=r"
upstream nodes { server {{server1}}:8000; server {{server2}}:8000; server {{server3}}:8000; } server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; server_name _; location / { proxy_pass http://nodes; } }
--- - hosts: web become: True vars_files: - group_vars/variables.yml pre_tasks: - debug: msg='Starting docker setup playbook' post_tasks: - debug: msg='Finished docker setup playbook' tasks: - name: Crear archivo plano file: path: /tmp/archivillo_2 state: touch mode: 0755 owner: ansible group: ansible - name: Crear un directorio file: path: /tmp/miDirectorio state: directory mode: 0700 owner: ansible group: ansible
Las Variables
vars.yml
nombre: Sergio Gabriel apellido: Guillen Mantilla var1: Valor de var1 db_user: ventas dB_password: ventas123
inventories/ production/ inventory.yml group_vars/ all.yml vars.yml development/ inventory.yml group_vars/ all.yml vars.yml roles/ role1/ role2/ role3/ playbook1.yml playbook2.yml playbook3.yml
21 reglas de precendencia
Los Sub Programas
roles/ common/ files/ templates/ tasks/ handlers/ vars/ defaults/ meta/
roles: - { role: base } - { role: web_base } - { role: lb_config, server1: "{{nodo1}}", server2: "{{nodo2}}", server3: "{{nodo3}}" }
Ansible y seguridad?