informatica:linux:docker:ansible
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:linux:docker:ansible [2017/02/16 22:50] – jose | informatica:linux:docker:ansible [2019/09/09 13:54] (current) – jose | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | < | ||
| + | proyecto | ||
| + | ├── inventories | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | │ | ||
| + | ├── main.yml | ||
| + | └── roles | ||
| + | └── create_user | ||
| + | ├── README.md | ||
| + | ├── defaults | ||
| + | │ | ||
| + | ├── files | ||
| + | ├── handlers | ||
| + | │ | ||
| + | ├── meta | ||
| + | │ | ||
| + | ├── tasks | ||
| + | │ | ||
| + | ├── templates | ||
| + | ├── tests | ||
| + | │ | ||
| + | │ | ||
| + | └── vars | ||
| + | └── main.yml | ||
| + | </ | ||
| + | Cada role lo creamos con: | ||
| + | ansible-galaxy init < | ||
| + | |||
| + | |||
| + | |||
| + | |||
| https:// | https:// | ||
| Line 10: | Line 51: | ||
| docker run --name ansible-1 --net ansible --ip 172.20.0.101 --hostname ansible1 -ti debian | docker run --name ansible-1 --net ansible --ip 172.20.0.101 --hostname ansible1 -ti debian | ||
| docker run --name ansible-2 --net ansible --ip 172.20.0.102 --hostname ansible2 -ti debian | docker run --name ansible-2 --net ansible --ip 172.20.0.102 --hostname ansible2 -ti debian | ||
| + | | ||
| + | | ||
| + | En el servidor de ansible creamos los grupos con las máquinas | ||
| + | / | ||
| + | |||
| + | [web] | ||
| + | 172.20.0.101 | ||
| + | 172.20.0.102 | ||
| + | |||
| + | Probamos si conecta: | ||
| + | ansible web -m ping | ||
| + | Fallará por no tener claves intercambiadas. Las intercambiamos y: | ||
| + | |||
| + | ansible web -m ping | ||
| + | < | ||
| + | |||
| + | 172.20.0.101 | SUCCESS => { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | 172.20.0.102 | SUCCESS => { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| | | ||
| + | ====== PLAYBOOKS ====== | ||
| + | Para ejecutar un playbook creamos el fichero yml y ejecutamos con -s si queremos sudo: | ||
| + | ansible-playbook <-s> playbook.yml | ||
| + | |||
| + | |||
| + | nginx.yml | ||
| + | |||
| + | < | ||
| + | --- | ||
| + | - hosts: prueba | ||
| + | tasks: | ||
| + | - name: Install Nginx | ||
| + | apt: pkg=nginx state=installed update_cache=true | ||
| + | |||
| + | </ | ||
| + | |||
| + | Ejemplo: | ||
| + | < | ||
| + | root@5b83b804b705: | ||
| + | |||
| + | PLAY [prueba] ****************************************************************** | ||
| + | |||
| + | TASK [setup] ******************************************************************* | ||
| + | ok: [172.17.0.3] | ||
| + | ok: [172.17.0.4] | ||
| + | |||
| + | TASK [Install Nginx] *********************************************************** | ||
| + | changed: [172.17.0.4] | ||
| + | changed: [172.17.0.3] | ||
| + | |||
| + | PLAY RECAP ********************************************************************* | ||
| + | 172.17.0.3 | ||
| + | 172.17.0.4 | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== Tarea dependiente ====== | ||
| + | Solo ejecuta la segunda tarea cuando ejecuta la primera. En este caso solo arranca nginx si lo instala: | ||
| + | < | ||
| + | - hosts: prueba | ||
| + | tasks: | ||
| + | - name: Install Nginx | ||
| + | apt: pkg=nginx state=installed update_cache=true | ||
| + | | ||
| + | - Start Nginx | ||
| + | |||
| + | handlers: | ||
| + | - name: Start Nginx | ||
| + | | ||
| + | </ | ||
| + | |||
| + | ====== Login con usuario ====== | ||
| + | Deshabilitamos la consulta del fingerprint | ||
| + | # uncomment this to disable SSH key host checking | ||
| + | host_key_checking = False | ||
| + | |||
| + | |||
informatica/linux/docker/ansible.1487285422.txt.gz · Last modified: by jose
