Taula de continguts

gestionar el sistema

3:37 Gestionar Sistema (I)

alternatives

gestión de /etc/alternatives
https://docs.ansible.com/ansible/latest/modules/alternatives_module.html#alternatives-module

- name: fijar la versión de Java a 8
  alternatives:
    name: java
    path: /usr/lib/jvm/java-8-openjdk-amd64/bin/java

/usr/bin/java/etc/alternatives/java/usr/lib/jvm/java-8-openjdk-amd64/bin/java

authorized_keys

https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html#authorized-key-module

- name: autorizar clave pública
  authorized_keys:
    user: <user>
    key: "..."

cron

https://docs.ansible.com/ansible/latest/modules/cron_module.html#cron-module

3:38 Gestionar Sistema (II)

filesystem

https://docs.ansible.com/ansible/latest/modules/filesystem_module.html#filesystem-module

- name: crear FS xfs
  filesystem:
    dev: /dev/sdX1
    fstype: xfs

firewalld

control del firewall en sistemas CentOS/RH
https://docs.ansible.com/ansible/latest/modules/firewalld_module.html#firewalld-module

- name: permitir acceso http/https
  firewalld:
    state: present
    service: "{{ item }}"
    permanent: true
  with_items:
    - "http"
    - "https"
- name: permitir acceso http/https
  firewalld:
    state: present
    service: "{{ item }}"
    permanent: true
  with_items:
    - "http"
    - "https"

group

https://docs.ansible.com/ansible/latest/modules/group_module.html#group-module

- name: crear grupo para aplicación
  group:
    name: jboss
    state: present
    gid: 185

hostname

https://docs.ansible.com/ansible/latest/modules/hostname_module.html#hostname-module

- name: cambiar el nombre del servidor
  hostname:
    name: servidor.dominio.com

ping ?

https://docs.ansible.com/ansible/latest/modules/ping_module.html#ping-module

- name: comprobar conexión
  ping:

timezone

https://docs.ansible.com/ansible/latest/modules/timezone_module.html#timezone-module

- name definir huso horario
  timezone:
    name: Europe/Barcelona

3:39 Gestionar Sistema (III)

iptables

https://docs.ansible.com/ansible/latest/modules/iptables_module.html#iptables-module

- name: permitir acceso puerto 80
  iptables:
    chain: INPUT
    source: 0.0.0.0
    destination_port: 80
    jump: ACCEPT
    protocol: tcp

lvg

https://docs.ansible.com/ansible/latest/modules/lvg_module.html#lvg-module

- name: crear grupo de volúmenes
  lvg:
    vg: datavg
    pvs: /dev/vda1
    state: present

vgs vgdisplay pvdisplay

lvol

https://docs.ansible.com/ansible/latest/modules/lvol_module.html#lvol-module

- name: creación volumen lógico
  lvol: vg=datavg lv=web size=2G state=present

lvscan

mount

https://docs.ansible.com/ansible/latest/modules/mount_module.html#mount-module

- name: montar partición WWW
  - filesystem: dev=/dev/datavg/web fstype=xfs # formatea
  - mount: src=/dev/datavg/web name=/var/www fstype=xfs # monta

3:40 Gestionar Sistema (IV)

service

https://docs.ansible.com/ansible/latest/modules/service_module.html#service-module

- name: iniciar y habilitar servicio
  service:
    name: apache2
    state: started
    enabled: true

setup

https://docs.ansible.com/ansible/latest/modules/setup_module.html#setup-module

- name: obtiene facts
  setup
   gather_subset: all

sysctl

cambios en el kernel
https://docs.ansible.com/ansible/latest/modules/sysctl_module.html#sysctl-module

- name: permitir redirigir el tráfico
  sysctl:
    name: net.ipv4.ip_forward
    value: 1
    sysctl_set: yes
    state: present
    reload: yes

sysctl -a | grep ip_forward

systemd

https://docs.ansible.com/ansible/latest/modules/systemd_module.html#systemd-module

- name: habilitar servicio y recargar systemd
  systemd:
    name: apache2
    enabled: yes
    state: started
    daemon_reload: yes

user

https://docs.ansible.com/ansible/latest/modules/user_module.html#user-module

- name: crear usuario
  user:
    name: pepito
    id: 1001
    home: /home/pepito
    shell: /bin/false
    state: present