Skip to content

Генерация /etc/hosts с помощью ansible

    - name: Generate /etc/hosts file
          src: templates/hosts.j2
          dest: /etc/hosts
        backup: yes
        tags: fist


# templates/hosts.j2
# {{ ansible_managed }}   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# Network nodes as generated through Ansible.
{% for host in play_hosts %}
{% if 'ansible_eth0' in hostvars[host] %}
{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}  {{ host }}
{% endif %}
{% endfor %}


domain_host1 ansible_host=
domain_host2 ansible_host=
domain_host3 ansible_host=


ЗЫ: не забываем включить gather_facts: yes

Published inOrchestration

Be First to Comment

Залишити відповідь

Ваша e-mail адреса не оприлюднюватиметься. Обов’язкові поля позначені *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.