]> git.phdru.name Git - ansible.git/commitdiff
Refactor: Join tasks into blocks to factor out conditions
authorOleg Broytman <phd@phdru.name>
Tue, 30 Jul 2019 18:27:32 +0000 (21:27 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 30 Jul 2019 18:27:32 +0000 (21:27 +0300)
playbooks/debian/roles/add-apache-vhost/tasks/main.yml
playbooks/debian/roles/add-dns-domain/tasks/main.yml
playbooks/debian/roles/apache/tasks/main.yml
playbooks/debian/roles/dehydrated/tasks/main.yml
playbooks/debian/roles/init-system/tasks/locales.yml
playbooks/debian/roles/named/tasks/main.yml
playbooks/debian/roles/remove-systemd/tasks/main.yml
playbooks/debian/roles/root/tasks/mc.yml

index 2f0e03a9209a0e0f3f549d19ee8fe91c15be81fb..511a67676a96f1019f5d7cff98fe096173c05655 100644 (file)
@@ -4,10 +4,9 @@
   register: vhost_conf
   changed_when: not vhost_conf.stat.exists
 
-- name: Add vhost
-  import_tasks: add-vhost.yml
-  when: not vhost_conf.stat.exists
-
-- name: Run dehydrated for the vhost
-  import_tasks: dehydrated.yml
+- block:
+    - name: Add vhost
+      import_tasks: add-vhost.yml
+    - name: Run dehydrated for the vhost
+      import_tasks: dehydrated.yml
   when: not vhost_conf.stat.exists
index 88a49c227ed2752ac0cb12356cad16284bcf69bd..a8c93fbe3cb0a0f822bff940f85cab109ffb1076 100644 (file)
@@ -4,33 +4,31 @@
   register: domain_exists
   changed_when: not domain_exists.stat.exists
 
-- name: Copy domain template
-  become: true
-  template:
-    src: domain
-    dest: "/etc/bind/{{ domain }}"
-    owner: bind
-    group: bind
-    mode: '0600'
-    force: no
-  when: not domain_exists.stat.exists
-
-- name: Update config
-  become: true
-  shell: |
-    echo 'zone "{{ domain }}" {
-          type master;
-          file "/etc/bind/{{ domain }}";
-          allow-query { any; };
-          notify yes;
-    };' >> /etc/bind/named.conf.local
+- block:
+    - name: Copy domain template
+      become: true
+      template:
+        src: domain
+        dest: "/etc/bind/{{ domain }}"
+        owner: bind
+        group: bind
+        mode: '0600'
+        force: no
 
+    - name: Update config
+      become: true
+      shell: |
+        echo 'zone "{{ domain }}" {
+              type master;
+              file "/etc/bind/{{ domain }}";
+              allow-query { any; };
+              notify yes;
+        };' >> /etc/bind/named.conf.local
 
-  when: not domain_exists.stat.exists
 
-- name: Reload BIND
-  become: true
-  service:
-    name: bind9
-    state: reloaded
+    - name: Reload BIND
+      become: true
+      service:
+        name: bind9
+        state: reloaded
   when: not domain_exists.stat.exists
index 5cd209acc7f0a7ebd876d87ef18803ce83e58e96..c05eb6f280fe6eb8d4cd2fb017349addea498664 100644 (file)
@@ -8,39 +8,37 @@
     msg: "apache has already been configured"
   when: phd_conf.stat.exists
 
-- name: Install apache
-  become: true
-  apt:
-    autoclean: yes
-    autoremove: yes
-    install_recommends: no
-    name: apache2
-    purge: yes
-    state: latest
-    update_cache: yes
-  when: not phd_conf.stat.exists
+- block:
+    - name: Install apache
+      become: true
+      apt:
+        autoclean: yes
+        autoremove: yes
+        install_recommends: no
+        name: apache2
+        purge: yes
+        state: latest
+        update_cache: yes
 
-- name: Enable SSL module
-  become: true
-  command: a2enmod ssl
-  notify: Reload apache
-  when: not phd_conf.stat.exists
+    - name: Enable SSL module
+      become: true
+      command: a2enmod ssl
+      notify: Reload apache
 
-- name: Configure apache
-  become: true
-  template:
-    src: 001-phd.conf
-    dest: /etc/apache2/conf-available
-    owner: root
-    group: root
-    mode: '0640'
-    force: no
-  when: not phd_conf.stat.exists
+    - name: Configure apache
+      become: true
+      template:
+        src: 001-phd.conf
+        dest: /etc/apache2/conf-available
+        owner: root
+        group: root
+        mode: '0640'
+        force: no
 
-- name: Enable config
-  become: true
-  command: a2enconf 001-phd
-  notify: Reload apache
+    - name: Enable config
+      become: true
+      command: a2enconf 001-phd
+      notify: Reload apache
   when: not phd_conf.stat.exists
 
 - name: Configure logrotate
index 87ebe8f05bd0eb9cde2931e4028f9e37f54cf48f..3405ff37245b6acfdaac15093bcac97f724cc8c2 100644 (file)
@@ -5,30 +5,30 @@
   register: dehydrated
   changed_when: not dehydrated.stat.exists
 
-- name: Install git
-  local_action:
-    module: apt
-    autoclean: yes
-    autoremove: yes
-    install_recommends: no
-    name: git
-    purge: yes
-    state: latest
-    update_cache: yes
-  when: not dehydrated.stat.exists
+- block:
+    - name: Install git
+      become: true
+      local_action:
+        module: apt
+        autoclean: yes
+        autoremove: yes
+        install_recommends: no
+        name: git
+        purge: yes
+        state: latest
+        update_cache: yes
 
-- name: Prepare to clone dehydrated
-  local_action:
-    module: file
-    path: /usr/local/src/LetsEncrypt
-    state: directory
-  when: not dehydrated.stat.exists
+    - name: Prepare to clone dehydrated
+      local_action:
+        module: file
+        path: /usr/local/src/LetsEncrypt
+        state: directory
 
-- name: Clone dehydrated
-  local_action:
-    module: git
-    repo: https://github.com/lukas2511/dehydrated.git
-    dest: /usr/local/src/LetsEncrypt/dehydrated
+    - name: Clone dehydrated
+      local_action:
+        module: git
+        repo: https://github.com/lukas2511/dehydrated.git
+        dest: /usr/local/src/LetsEncrypt/dehydrated
   when: not dehydrated.stat.exists
 
 - name: Prepare the server to syncronize dehydrated
index 81434078bcee66d0d8dc50e766c5fbf82ba4b7c3..8351b6005fa04be46b8626bc50d75bd63a9823e1 100644 (file)
@@ -7,20 +7,19 @@
     msg: "Locales have already been configured"
   when: has_locales.stdout != "0"
 
-- name: Configure locales
-  become: true
-  lineinfile:
-    path: /etc/locale.gen
-    regexp: "^{{ item }}"
-    line: "{{ item }}"
-  loop: [
-      'en_US ISO-8859-1',
-      'ru_RU.KOI8-R KOI8-R',
-      'ru_RU.UTF-8 UTF-8',
-  ]
-  when: has_locales.stdout == "0"
-
-- name: Regenerate locales
-  become: true
-  command: /usr/sbin/locale-gen
+- block:
+    - name: Configure locales
+      become: true
+      lineinfile:
+        path: /etc/locale.gen
+        regexp: "^{{ item }}"
+        line: "{{ item }}"
+      loop: [
+          'en_US ISO-8859-1',
+          'ru_RU.KOI8-R KOI8-R',
+          'ru_RU.UTF-8 UTF-8',
+      ]
+    - name: Regenerate locales
+      become: true
+      command: /usr/sbin/locale-gen
   when: has_locales.stdout == "0"
index b39eda30ceead641e07f1cfd5da7bd4f9e0645cb..8c6b7d0f9e6048c1cb69f5ac2d3e7a5ce5aab59d 100644 (file)
@@ -8,31 +8,30 @@
     msg: "BIND has already been configured"
   when: named_conf.stdout not in ('', "0")
 
-- name: Install BIND
-  become: true
-  apt:
-    autoclean: yes
-    autoremove: yes
-    install_recommends: no
-    name: bind9
-    purge: yes
-    state: latest
-    update_cache: yes
-  when: named_conf.stdout in ('', "0")
+- block:
+    - name: Install BIND
+      become: true
+      apt:
+        autoclean: yes
+        autoremove: yes
+        install_recommends: no
+        name: bind9
+        purge: yes
+        state: latest
+        update_cache: yes
 
-- name: Configure BIND
-  become: true
-  copy:
-    src: named.conf.options
-    dest: /etc/bind/named.conf.options
-    owner: bind
-    group: bind
-    mode: '0600'
-  when: named_conf.stdout in ('', "0")
+    - name: Configure BIND
+      become: true
+      copy:
+        src: named.conf.options
+        dest: /etc/bind/named.conf.options
+        owner: bind
+        group: bind
+        mode: '0600'
 
-- name: Reload BIND
-  become: true
-  service:
-    name: bind9
-    state: reloaded
+    - name: Reload BIND
+      become: true
+      service:
+        name: bind9
+        state: reloaded
   when: named_conf.stdout in ('', "0")
index 76ff12589bb11e0d5d64af076fd6f12181a6a0b8..1739c6c874df95be0a3c8a7e38935532535028af 100644 (file)
 - name: Purge SystemD
   import_tasks: remove-systemd.yml
 
-- name: Reboot if SystemD is still active
-  become: true
-  reboot:
-  when: "'rc' in purged and purged.rc != 0"
-
-- name: Purge SystemD after reboot
-  import_tasks: remove-systemd.yml
+- block:
+    - name: Reboot if SystemD is still active
+      become: true
+      reboot:
+    - name: Purge SystemD after reboot
+      import_tasks: remove-systemd.yml
   when: "'rc' in purged and purged.rc != 0"
index 332015ef7d3facd2480290e9d892eaca816480ac..c27e80e99d076681ad6c51e1e000b178063a7a3b 100644 (file)
     msg: "mc links have already been created"
   when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length == 3
 
-- name: "Setup root mc - create directories for mc links"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: directory
-    mode: "0700"
-  loop: ['.cache', '.config', '.local/share']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+- block:
+    - name: "Setup root mc - create directories for mc links"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: directory
+        mode: "0700"
+      loop: ['.cache', '.config', '.local/share']
 
-- name: "Setup root mc - remove mc directories"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: absent
-  loop: ['.cache/mc', '.config/mc', '.local/share/mc']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+    - name: "Setup root mc - remove mc directories"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: absent
+      loop: ['.cache/mc', '.config/mc', '.local/share/mc']
 
-- name: "Setup root mc - link mc directories (1)"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: link
-    src: "../.mc"
-    force: yes
-  loop: ['.cache/mc', '.config/mc']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+    - name: "Setup root mc - link mc directories (1)"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: link
+        src: "../.mc"
+        force: yes
+      loop: ['.cache/mc', '.config/mc']
 
-- name: "Setup root mc - link mc directories (2)"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: link
-    src: "../../.mc"
-    force: yes
-  loop: ['.local/share/mc']
+    - name: "Setup root mc - link mc directories (2)"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: link
+        src: "../../.mc"
+        force: yes
+      loop: ['.local/share/mc']
   when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
 - name: "Setup root mc - overwrite files from ~phd/admin"