Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
Ambdós costats versió prèvia Revisió prèvia Següent revisió | Revisió prèvia | ||
info:cursos:pue:devops:sesion6 [02/03/2019 00:06] – [Sesin 6 : ansible] mate | info:cursos:pue:devops:sesion6 [02/03/2019 05:04] (actual) – [Prometheus] mate | ||
---|---|---|---|
Línia 1: | Línia 1: | ||
= Sesión 6 : ansible | = Sesión 6 : ansible | ||
== ansible | == ansible | ||
- | * become: | + | === become |
- | | + | <code yaml> |
- name: servicio | - name: servicio | ||
service: | service: | ||
Línia 9: | Línia 9: | ||
become: yes | become: yes | ||
</ | </ | ||
- | * <code yaml> | + | <code yaml> |
- name: servicio | - name: servicio | ||
service: | service: | ||
Línia 17: | Línia 17: | ||
become_user: | become_user: | ||
</ | </ | ||
+ | |||
+ | === adduser | ||
+ | <code yaml; add-user.yaml> | ||
+ | - hosts: all | ||
+ | tasks: | ||
+ | - include: add-user-debian.yaml | ||
+ | when: ansible_os_family == ' | ||
+ | - include: add-user-redhat.yaml | ||
+ | when: ansible_os_family == ' | ||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-debian.yaml> | ||
+ | - name: add user | ||
+ | user: | ||
+ | name: operador | ||
+ | comment: nuestro usuario operador | ||
+ | shell: /bin/bash | ||
+ | home: / | ||
+ | groups: sudo | ||
+ | append: yes | ||
+ | become: true | ||
+ | |||
+ | - name: Set authorized key taken from file | ||
+ | authorized_key: | ||
+ | user: operador | ||
+ | state: present | ||
+ | key: "{{ lookup(' | ||
+ | become: true | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-redhat.yaml> | ||
+ | - name: check centos correct suoders line | ||
+ | lineinfile: | ||
+ | path: / | ||
+ | state: present | ||
+ | regexp: ' | ||
+ | line: ' | ||
+ | become: true | ||
+ | when: ansible_os_family == ' | ||
+ | - name: add user | ||
+ | user: | ||
+ | name: operador | ||
+ | comment: nuestro usuario operador | ||
+ | shell: /bin/bash | ||
+ | home: / | ||
+ | groups: wheel | ||
+ | append: yes | ||
+ | become: true | ||
+ | |||
+ | - name: Set authorized key taken from file | ||
+ | authorized_key: | ||
+ | user: operador | ||
+ | state: present | ||
+ | key: "{{ lookup(' | ||
+ | become: true | ||
+ | </ | ||
+ | |||
+ | === adduser2 | ||
+ | <code yaml; otra-opcion.yaml> | ||
+ | - hosts: " | ||
+ | sudo: true | ||
+ | vars: | ||
+ | users: | ||
+ | - " | ||
+ | - " | ||
+ | - " | ||
+ | tasks: | ||
+ | - name: "crear grupo operador" | ||
+ | become: yes | ||
+ | group: | ||
+ | name: operador | ||
+ | state: present | ||
+ | |||
+ | - name: " | ||
+ | user: | ||
+ | name: "{{ item }}" | ||
+ | groups: " | ||
+ | with_items: "{{ users }}" | ||
+ | |||
+ | - name: "Add authorized keys" | ||
+ | authorized_key: | ||
+ | user: "{{ item }}" | ||
+ | key: "{{ lookup(' | ||
+ | with_items: "{{ users }}" | ||
+ | |||
+ | - name: "Allow admin users to sudo without a password" | ||
+ | lineinfile: | ||
+ | dest: "/ | ||
+ | state: " | ||
+ | regexp: " | ||
+ | line: " | ||
+ | become: yes | ||
+ | |||
+ | - name: Install apache httpd but avoid starting it immediately (state=present is optional) | ||
+ | | ||
+ | name: httpd | ||
+ | when: ansible_os_family == ' | ||
+ | | ||
+ | </ | ||
+ | |||
+ | === mysql install | ||
+ | <code yaml; mysql-install.yaml> | ||
+ | # Ansible needs python-mysqldb | ||
+ | - name: Install MySQL | ||
+ | apt: pkg={{item}} state=latest update_cache=false | ||
+ | register: ispconfig_install_step1 | ||
+ | with_items: | ||
+ | - pwgen | ||
+ | - mysql-client | ||
+ | - mysql-server | ||
+ | - python-mysqldb | ||
+ | |||
+ | # Requires a system with pwgen, included in our base system | ||
+ | - name: Generate MySQL Random Password | ||
+ | command: / | ||
+ | register: mysql_root_password | ||
+ | |||
+ | - name: update mysql root password for all root accounts | ||
+ | mysql_user: name=root host={{ item }} password={{mysql_root_password.stdout}} | ||
+ | with_items: | ||
+ | - "{{ inventory_hostname }}" | ||
+ | - 127.0.0.1 | ||
+ | - ::1 | ||
+ | - localhost | ||
+ | notify: | ||
+ | - Restart MySQL | ||
+ | |||
+ | - name: copy my.cnf file with root password credentials to / | ||
+ | template: src=my.cnf dest=/ | ||
+ | |||
+ | - name: Configure MySQL to listen on *:3306 | ||
+ | replace: dest=/ | ||
+ | </ | ||
+ | * [[https:// | ||
+ | |||
+ | === roles | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | <code yaml> | ||
+ | - hosts: all | ||
+ | roles: | ||
+ | - rol1 | ||
+ | - rol2 | ||
+ | - rol3 | ||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-with-rol.yaml> | ||
+ | - hosts: all | ||
+ | roles: | ||
+ | - add-user-rol | ||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-rol/ | ||
+ | - include: add-user-debian.yaml | ||
+ | when: ansible_os_family == ' | ||
+ | - include: add-user-redhat.yaml | ||
+ | when: ansible_os_family == ' | ||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-rol/ | ||
+ | - name: add user | ||
+ | user: | ||
+ | name: operador | ||
+ | comment: nuestro usuario operador | ||
+ | shell: /bin/bash | ||
+ | home: / | ||
+ | groups: sudo | ||
+ | append: yes | ||
+ | become: true | ||
+ | |||
+ | - name: Set authorized key taken from file | ||
+ | authorized_key: | ||
+ | user: operador | ||
+ | state: present | ||
+ | # la clave pública en el directorio files del rol | ||
+ | key: "{{ lookup(' | ||
+ | become: true | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code yaml; add-user-rol/ | ||
+ | - name: check centos correct suoders line | ||
+ | lineinfile: | ||
+ | path: / | ||
+ | state: present | ||
+ | regexp: ' | ||
+ | line: ' | ||
+ | become: true | ||
+ | when: ansible_os_family == ' | ||
+ | - name: add user | ||
+ | user: | ||
+ | name: operador | ||
+ | comment: nuestro usuario operador | ||
+ | shell: /bin/bash | ||
+ | home: / | ||
+ | groups: wheel | ||
+ | append: yes | ||
+ | become: true | ||
+ | |||
+ | - name: Set authorized key taken from file | ||
+ | authorized_key: | ||
+ | user: operador | ||
+ | state: present | ||
+ | key: "{{ lookup(' | ||
+ | become: true | ||
+ | </ | ||
+ | |||
+ | == git | ||
+ | * HEAD : RAMA+COMMIT | ||
+ | * HEAD~2 : 2 commits atrás del HEAD actual | ||
+ | * comandos | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | == docker-machine | ||
+ | instalar docker en máquinas de diferentes proveedores: | ||
+ | * máquina remota | ||
+ | * digital-ocean | ||
+ | * amazonec2 | ||
+ | |||
+ | info: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | comandos: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * <code bash> | ||
+ | --driver generic \ | ||
+ | --generic-ip-address=203.0.113.81 \ | ||
+ | --generic-ssh-key ~/ | ||
+ | vm</ | ||
+ | |||
+ | **boot2docker.iso** : imagen usada en el driver por defecto para lanzar un docker. Usada en windows/mac | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | == Prometheus | ||
+ | * [[https:// | ||
+ | * monitoring stack | ||
+ | * federados + árbol | ||
+ | * alertar por umbrales -> alertmanager | ||
+ | * recepción de métricas de monitorización -> pushgateway | ||
+ | * se usa Grafana para acceder a los datos | ||
+ | * origen de las métricas: | ||
+ | * node_exporter | ||
+ | * cadvisor prometheus | ||
+ | * docker metrics | ||
+ | * despliegue en docker swarm: [[https:// | ||
+ | == otros | ||
+ | * '' | ||
+ | * [[https:// | ||
+ | * vim-nox | ||
+ | * no confirmar claves de sistemas remotos:< | ||
+ | host * | ||
+ | StrictHostKeyChecking no</ | ||
+ | * TICK : Telegraf + InfluxDB + Chronograf + Kapacitor | ||
+ | {{ : | ||
+ | * [[https:// |