diff --git a/blogs.yaml b/blogs.yaml index ec1ff63..2c7fbe4 100644 --- a/blogs.yaml +++ b/blogs.yaml @@ -8,6 +8,7 @@ ansible_docker_extra_args: blogs - hosts: blogs roles: + - role: dns_record - role: wordpress site_names: - kaos diff --git a/ldap.yaml b/ldap.yaml index 349d745..3886082 100644 --- a/ldap.yaml +++ b/ldap.yaml @@ -8,6 +8,7 @@ ansible_docker_extra_args: ldap - hosts: ldap roles: + - role: dns_record - role: ldap ldap_domain: 'lilik.it' ldap_organization: 'LILiK' diff --git a/lists.yaml b/lists.yaml index cef9fc7..de422d7 100644 --- a/lists.yaml +++ b/lists.yaml @@ -8,4 +8,5 @@ ansible_docker_extra_args: lists - hosts: lists roles: + - role: dns_record - role: sympa diff --git a/mail.yaml b/mail.yaml index e25dda8..ee7655b 100644 --- a/mail.yaml +++ b/mail.yaml @@ -8,6 +8,7 @@ ansible_docker_extra_args: mail - hosts: mail roles: + - role: dns_record - role: postfix ldap_server: "{{ hostvars['ldap'].ansible_host }}" fqdn_domain: "mail.lilik.it" diff --git a/projects.yaml b/projects.yaml index d324e1c..29e8d04 100644 --- a/projects.yaml +++ b/projects.yaml @@ -9,4 +9,5 @@ ansible_docker_extra_args: projects - hosts: projects roles: + - role: dns_record - role: gitlab diff --git a/roles/dns_record/tasks/main.yaml b/roles/dns_record/tasks/main.yaml new file mode 100644 index 0000000..268bb7b --- /dev/null +++ b/roles/dns_record/tasks/main.yaml @@ -0,0 +1,12 @@ +- name: + lineinfile: + dest: '/etc/hosts' + line: '{{ ansible_default_ipv4.address }} {{ ansible_hostname }}' + regexp: '^\s*\S* {{ ansible_hostname }}' + delegate_to: gandalf2 + register: hosts + +- name: restart dnsmasq + shell: "/etc/init.d/dnsmasq restart" + delegate_to: gandalf2 + when: hosts.changed diff --git a/roles/lxc_guest/tasks/main.yaml b/roles/lxc_guest/tasks/main.yaml index 027fa65..1aa42f7 100644 --- a/roles/lxc_guest/tasks/main.yaml +++ b/roles/lxc_guest/tasks/main.yaml @@ -68,9 +68,9 @@ verbosity: 2 - name: update container DNS configuration - shell: lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "grep '^nameserver {{ hostvars[ext_gateway].ansible_host }}$' /etc/resolv.conf || echo 'nameserver {{ hostvars[ext_gateway].ansible_host }}' > /etc/resolv.conf" + shell: lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "grep -Pz1 'domain lilik.it\nnameserver {{ hostvars[ext_gateway].ansible_host }}' /etc/resolv.conf || echo -e 'domain lilik.it\nnameserver {{ hostvars[ext_gateway].ansible_host }}' > /etc/resolv.conf" register: container_dns_configuration - changed_when: "container_dns_configuration.stdout != 'nameserver {{ hostvars[ext_gateway].ansible_host }}'" + changed_when: container_dns_configuration.stdout != "domain lilik.it\nnameserver {{ hostvars[ext_gateway].ansible_host }}\n\u0000" - name: update container network configuration shell: lxc-attach -n {{ vm_name }} --clear-env -e -- bash -c "grep -F 'iface eth0 inet manual' /etc/network/interfaces || sed -i 's/iface eth0 inet dhcp/iface eth0 inet manual/' /etc/network/interfaces" diff --git a/users.yaml b/users.yaml index f055d7d..7bb49be 100644 --- a/users.yaml +++ b/users.yaml @@ -8,6 +8,7 @@ ansible_docker_extra_args: users - hosts: users roles: + - role: dns_record - role: fail2ban - role: pam-ldap ldap_server: "{{ hostvars['ldap'].ansible_host }}" diff --git a/webmail.yaml b/webmail.yaml index 0884dbf..9e814d1 100644 --- a/webmail.yaml +++ b/webmail.yaml @@ -8,5 +8,6 @@ ansible_docker_extra_args: webmail - hosts: webmail roles: + - role: dns_record - role: roundcube mail_server: "mail.lilik.it" diff --git a/wiki.yaml b/wiki.yaml index cb7bb83..6d315ba 100644 --- a/wiki.yaml +++ b/wiki.yaml @@ -8,4 +8,5 @@ ansible_docker_extra_args: wiki - hosts: wiki roles: + - role: dns_record - role: dokuwiki