computers.yml 780 B

123456789101112131415161718192021222324252627
  1. ---
  2. - name: Actualizar el archivo /etc/hosts en todos los equipos del inventario
  3. hosts: equipos
  4. become: yes
  5. tasks:
  6. - name: Leer el contenido actual del archivo /etc/hosts
  7. ansible.builtin.slurp:
  8. path: /etc/hosts
  9. register: current_hosts
  10. - name: Generar el contenido actualizado del archivo /etc/hosts
  11. ansible.builtin.template:
  12. src: templates/hosts.j2
  13. dest: /etc/hosts
  14. owner: root
  15. group: root
  16. mode: '0644'
  17. vars:
  18. current_hosts_content: "{{ current_hosts.content | b64decode }}"
  19. notify:
  20. - Reiniciar servicio de red si es necesario
  21. handlers:
  22. - name: Reiniciar servicio de red si es necesario
  23. ansible.builtin.service:
  24. name: network
  25. state: restarted