From f0661e4d80d614401d75e1a38eba3918315debdd Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 30 Jul 2019 01:45:43 +0300 Subject: [PATCH] Feat: Gather facts and use default IPv4 address --- playbooks/debian-add-apache-vhost | 3 ++- playbooks/debian-add-dns-domain | 3 ++- .../roles/add-apache-vhost/templates/vhost.conf | 8 ++++---- .../debian/roles/add-dns-domain/tasks/main.yml | 15 +++++++-------- .../debian/roles/add-dns-domain/templates/domain | 4 ++-- .../debian/roles/apache/templates/001-phd.conf | 10 +++++----- playbooks/debian/roles/named/tasks/main.yml | 2 +- playbooks/run-role.yml | 2 +- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/playbooks/debian-add-apache-vhost b/playbooks/debian-add-apache-vhost index 59eb749..8228910 100755 --- a/playbooks/debian-add-apache-vhost +++ b/playbooks/debian-add-apache-vhost @@ -10,4 +10,5 @@ shift cd "`dirname \"$0\"`" && ANSIBLE_ROLES_PATH=debian/roles \ - exec ./run-role add-apache-vhost "$@" -e virtual_host="$vhost" + exec ./run-role add-apache-vhost "$@" \ + -e virtual_host="$vhost" -e gather_facts=true diff --git a/playbooks/debian-add-dns-domain b/playbooks/debian-add-dns-domain index b4b865c..57ed031 100755 --- a/playbooks/debian-add-dns-domain +++ b/playbooks/debian-add-dns-domain @@ -10,4 +10,5 @@ shift cd "`dirname \"$0\"`" && ANSIBLE_ROLES_PATH=debian/roles \ - exec ./run-role add-dns-domain "$@" -e domain="$domain" + exec ./run-role add-dns-domain "$@" \ + -e domain="$domain" -e gather_facts=true diff --git a/playbooks/debian/roles/add-apache-vhost/templates/vhost.conf b/playbooks/debian/roles/add-apache-vhost/templates/vhost.conf index 2f3dd5b..3ca21de 100644 --- a/playbooks/debian/roles/add-apache-vhost/templates/vhost.conf +++ b/playbooks/debian/roles/add-apache-vhost/templates/vhost.conf @@ -1,18 +1,18 @@ - + ServerName {{ virtual_host }} Redirect permanent / https://{{ virtual_host }}/ ErrorLog /var/log/apache2/{{ virtual_host }}/error_log CustomLog /var/log/apache2/{{ virtual_host }}/access_log common - + ServerName www.{{ virtual_host }} Redirect permanent / https://{{ virtual_host }}/ ErrorLog /var/log/apache2/{{ virtual_host }}/error_log CustomLog /var/log/apache2/{{ virtual_host }}/access_log common - + ServerName {{ virtual_host }} DocumentRoot /home/phd/Internet/WWW/htdocs/{{ virtual_host }} @@ -88,7 +88,7 @@ BrowserMatch "MSIE [2-6]" \ BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown - + ServerName www.{{ virtual_host }} Redirect permanent / https://{{ virtual_host }}/ ErrorLog /var/log/apache2/{{ virtual_host }}/error_log diff --git a/playbooks/debian/roles/add-dns-domain/tasks/main.yml b/playbooks/debian/roles/add-dns-domain/tasks/main.yml index 8837d99..422f28e 100644 --- a/playbooks/debian/roles/add-dns-domain/tasks/main.yml +++ b/playbooks/debian/roles/add-dns-domain/tasks/main.yml @@ -17,15 +17,14 @@ - name: Update config become: true shell: | -echo ' + echo ' -zone "{{ domain }}" { - type master; - file "/etc/bind/{{ domain }}"; - allow-query { any; }; - notify yes; -}; -' >> /etc/bind/named.conf.local + zone "{{ domain }}" { + type master; + file "/etc/bind/{{ domain }}"; + allow-query { any; }; + notify yes; + };' >> /etc/bind/named.conf.local when: not domain_exists.stat.exists diff --git a/playbooks/debian/roles/add-dns-domain/templates/domain b/playbooks/debian/roles/add-dns-domain/templates/domain index e2dcd32..1bc0913 100644 --- a/playbooks/debian/roles/add-dns-domain/templates/domain +++ b/playbooks/debian/roles/add-dns-domain/templates/domain @@ -7,6 +7,6 @@ $TTL 86400 86400) ; Default TTL 1d IN NS ns1.{{ domain }}. - IN A ??? -ns1 IN A ??? + IN A {{ ansible_facts.default_ipv4.address }} +ns1 IN A {{ ansible_facts.default_ipv4.address }} www IN CNAME {{ domain }}. diff --git a/playbooks/debian/roles/apache/templates/001-phd.conf b/playbooks/debian/roles/apache/templates/001-phd.conf index 5eb26f6..1547854 100644 --- a/playbooks/debian/roles/apache/templates/001-phd.conf +++ b/playbooks/debian/roles/apache/templates/001-phd.conf @@ -34,7 +34,7 @@ AddDefaultCharset koi8-r AuthName Apache AuthUserFile /usr/local/apache2/data/apache.passwd - Require ip 127.0.0.1 {{ inventory_hostname }} + Require ip 127.0.0.1 {{ ansible_facts.default_ipv4.address }} Require user phd @@ -62,21 +62,21 @@ Scriptsock data/cgisock SetHandler server-info - Require ip 127.0.0.1 {{ inventory_hostname }} + Require ip 127.0.0.1 {{ ansible_facts.default_ipv4.address }} SetHandler server-status - Require ip 127.0.0.1 {{ inventory_hostname }} + Require ip 127.0.0.1 {{ ansible_facts.default_ipv4.address }} ExtendedStatus On - Require ip 127.0.0.1 {{ inventory_hostname }} + Require ip 127.0.0.1 {{ ansible_facts.default_ipv4.address }} @@ -107,7 +107,7 @@ RemoveHandler .py ErrorDocument 404 /~phd/Bookmarks/notfound.html - + ServerName unknown.invalid DocumentRoot /home/phd/Internet/WWW/htdocs/_default_/ ErrorDocument 404 /nothing.html diff --git a/playbooks/debian/roles/named/tasks/main.yml b/playbooks/debian/roles/named/tasks/main.yml index 9c6d038..092d531 100644 --- a/playbooks/debian/roles/named/tasks/main.yml +++ b/playbooks/debian/roles/named/tasks/main.yml @@ -1,5 +1,5 @@ - name: Check named.conf.options - shell: "grep -c '^[ \\t]\\+allow-query' /etc/bind/named.conf.options || :" + shell: "grep -c '^[ \\t]\\+allow-query' /etc/bind/named.conf.options || echo 0" register: named_conf changed_when: named_conf.stdout == "0" diff --git a/playbooks/run-role.yml b/playbooks/run-role.yml index bc17964..bf25886 100644 --- a/playbooks/run-role.yml +++ b/playbooks/run-role.yml @@ -1,5 +1,5 @@ - name: "Run role {{ role }}" hosts: "{{ hosts | default('all') }}" - gather_facts: false + gather_facts: "{{ gather_facts | default('false') }}" roles: - "{{ role }}" -- 2.39.2