From debc4a82caefda148aaa8f6e3e1bcaf0419a46c1 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 4 May 2021 13:39:47 +0200 Subject: [PATCH] Use 'loop' syntax instead of 'with_first_found' --- CHANGELOG.md | 1 + evobackup-client/tasks/upload_scripts.yml | 12 ++++---- evolinux-base/tasks/motd.yml | 6 ++-- filebeat/tasks/main.yml | 6 ++-- haproxy/tasks/main.yml | 8 ++--- logstash/tasks/main.yml | 12 ++++---- metricbeat/tasks/main.yml | 6 ++-- minifirewall/tasks/tail.yml | 12 ++++---- varnish/tasks/main.yml | 20 +++++++------ webapps/evoadmin-web/tasks/config.yml | 18 +++++++----- webapps/evoadmin-web/tasks/user.yml | 12 ++++---- webapps/evoadmin-web/tasks/web.yml | 36 +++++++++++++---------- 12 files changed, 87 insertions(+), 62 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2390187a..a6bbfc1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ The **patch** part changes incrementally at each release. ### Changed +* Use 'loop' syntax instead of 'with_first_found' * apt: store keys in /etc/apt/trusted.gpg.d in ascii format * evolinux-base: copy GPG key instead of using apt-key * ntpd: Add leapfile configuration setting to ntpd on debian 10+ diff --git a/evobackup-client/tasks/upload_scripts.yml b/evobackup-client/tasks/upload_scripts.yml index 8d698519..f3f7de25 100644 --- a/evobackup-client/tasks/upload_scripts.yml +++ b/evobackup-client/tasks/upload_scripts.yml @@ -6,11 +6,13 @@ dest: "{{ evobackup_client__cron_path }}" force: true mode: 0755 - with_first_found: - - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.{{ inventory_hostname }}.sh.j2" - - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.{{ host_group }}.sh.j2" - - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.sh.j2" - - "zzz_evobackup.default.sh.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.{{ inventory_hostname }}.sh.j2" + - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.{{ host_group }}.sh.j2" + - "templates/evobackup-client/{{ evobackup_client__cron_template_name }}.sh.j2" + - "templates/zzz_evobackup.default.sh.j2" tags: - evobackup_client - evobackup_client_backup_scripts diff --git a/evolinux-base/tasks/motd.yml b/evolinux-base/tasks/motd.yml index d1171eb4..59076f8e 100644 --- a/evolinux-base/tasks/motd.yml +++ b/evolinux-base/tasks/motd.yml @@ -7,11 +7,11 @@ owner: root group: root mode: "0644" - with_first_found: - - files: + loop: "{{ query('first_found', templates, errors='ignore') }}" + vars: + templates: - "motd/motd.{{ inventory_hostname }}.j2" - "motd/motd.{{ host_group }}.j2" - "motd/motd.default.j2" - skip: True tags: - motd diff --git a/filebeat/tasks/main.yml b/filebeat/tasks/main.yml index c86e0e63..283ba1ce 100644 --- a/filebeat/tasks/main.yml +++ b/filebeat/tasks/main.yml @@ -145,11 +145,13 @@ src: "{{ item }}" dest: /etc/filebeat/filebeat.yml force: "{{ filebeat_force_config }}" - with_first_found: + loop: "{{ query('first_found', templates) }}" + vars: + templates: - "templates/filebeat/filebeat.{{ inventory_hostname }}.yml.j2" - "templates/filebeat/filebeat.{{ host_group }}.yml.j2" - "templates/filebeat/filebeat.default.yml.j2" - - "filebeat.default.yml.j2" + - "templates/filebeat.default.yml.j2" notify: restart filebeat when: filebeat_update_config when: filebeat_use_config_template diff --git a/haproxy/tasks/main.yml b/haproxy/tasks/main.yml index 9e6936b5..8b47127b 100644 --- a/haproxy/tasks/main.yml +++ b/haproxy/tasks/main.yml @@ -103,10 +103,10 @@ loop: "{{ query('first_found', templates) }}" vars: templates: - - "templates/haproxy/haproxy.{{ inventory_hostname }}.cfg.j2" - - "templates/haproxy/haproxy.{{ host_group | default('all') }}.cfg.j2" - - "templates/haproxy/haproxy.default.cfg.j2" - - "haproxy.default.cfg.j2" + - "templates/haproxy/haproxy.{{ inventory_hostname }}.cfg.j2" + - "templates/haproxy/haproxy.{{ host_group | default('all') }}.cfg.j2" + - "templates/haproxy/haproxy.default.cfg.j2" + - "templates/haproxy.default.cfg.j2" notify: reload haproxy when: haproxy_update_config tags: diff --git a/logstash/tasks/main.yml b/logstash/tasks/main.yml index d0e26208..1160711d 100644 --- a/logstash/tasks/main.yml +++ b/logstash/tasks/main.yml @@ -72,11 +72,13 @@ group: logstash mode: "0640" force: yes - with_first_found: - - "templates/logstash/logstash.{{ inventory_hostname }}.conf.j2" - - "templates/logstash/logstash.{{ host_group }}.conf.j2" - - "templates/logstash/logstash.default.conf.j2" - - "logstash.default.conf.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/logstash/logstash.{{ inventory_hostname }}.conf.j2" + - "templates/logstash/logstash.{{ host_group }}.conf.j2" + - "templates/logstash/logstash.default.conf.j2" + - "templates/logstash.default.conf.j2" register: logstash_template - debug: diff --git a/metricbeat/tasks/main.yml b/metricbeat/tasks/main.yml index cbb5e0e6..a4706046 100644 --- a/metricbeat/tasks/main.yml +++ b/metricbeat/tasks/main.yml @@ -119,11 +119,13 @@ src: "{{ item }}" dest: /etc/metricbeat/metricbeat.yml force: "{{ metricbeat_force_config }}" - with_first_found: + loop: "{{ query('first_found', templates) }}" + vars: + templates: - "templates/metricbeat/metricbeat.{{ inventory_hostname }}.yml.j2" - "templates/metricbeat/metricbeat.{{ host_group }}.yml.j2" - "templates/metricbeat/metricbeat.default.yml.j2" - - "metricbeat.default.yml.j2" + - "templates/metricbeat.default.yml.j2" notify: restart metricbeat when: metricbeat_update_config when: metricbeat_use_config_template diff --git a/minifirewall/tasks/tail.yml b/minifirewall/tasks/tail.yml index 1f6b715d..629c2e59 100644 --- a/minifirewall/tasks/tail.yml +++ b/minifirewall/tasks/tail.yml @@ -4,11 +4,13 @@ src: "{{ item }}" dest: "{{ minifirewall_tail_file }}" force: "{{ minifirewall_tail_force | bool }}" - with_first_found: - - "templates/minifirewall-tail/minifirewall.{{ inventory_hostname }}.tail.j2" - - "templates/minifirewall-tail/minifirewall.{{ host_group }}.tail.j2" - - "templates/minifirewall-tail/minifirewall.default.tail.j2" - - "minifirewall.default.tail.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/minifirewall-tail/minifirewall.{{ inventory_hostname }}.tail.j2" + - "templates/minifirewall-tail/minifirewall.{{ host_group }}.tail.j2" + - "templates/minifirewall-tail/minifirewall.default.tail.j2" + - "templates/minifirewall.default.tail.j2" register: minifirewall_tail_template - debug: diff --git a/varnish/tasks/main.yml b/varnish/tasks/main.yml index 035ae4a4..a8f9fa80 100644 --- a/varnish/tasks/main.yml +++ b/varnish/tasks/main.yml @@ -84,15 +84,17 @@ dest: "{{ varnish_config_file }}" mode: "0644" force: yes - with_first_found: - - "templates/varnish/varnish.{{ inventory_hostname }}.vcl.j2" - - "templates/varnish/default.{{ inventory_hostname }}.vcl.j2" - - "templates/varnish/varnish.{{ host_group }}.vcl.j2" - - "templates/varnish/default.{{ host_group }}.vcl.j2" - - "templates/varnish/varnish.default.vcl.j2" - - "templates/varnish/default.default.vcl.j2" - - "varnish.vcl.j2" - - "default.vcl.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/varnish/varnish.{{ inventory_hostname }}.vcl.j2" + - "templates/varnish/default.{{ inventory_hostname }}.vcl.j2" + - "templates/varnish/varnish.{{ host_group }}.vcl.j2" + - "templates/varnish/default.{{ host_group }}.vcl.j2" + - "templates/varnish/varnish.default.vcl.j2" + - "templates/varnish/default.default.vcl.j2" + - "templates/varnish.vcl.j2" + - "templates/default.vcl.j2" notify: reload varnish tags: - varnish diff --git a/webapps/evoadmin-web/tasks/config.yml b/webapps/evoadmin-web/tasks/config.yml index 689a217e..9f16a2d6 100644 --- a/webapps/evoadmin-web/tasks/config.yml +++ b/webapps/evoadmin-web/tasks/config.yml @@ -11,11 +11,13 @@ src: "{{ item }}" dest: /etc/evolinux/web-add.conf force: "{{ evoadmin_add_conf_force }}" - with_first_found: + loop: "{{ query('first_found', templates) }}" + vars: + templates: - "templates/evoadmin-web/web-add.{{ inventory_hostname }}.conf.j2" - "templates/evoadmin-web/web-add.{{ host_group }}.conf.j2" - "templates/evoadmin-web/web-add.conf.j2" - - "web-add.conf.j2" + - "templates/web-add.conf.j2" register: evoadmin_add_conf_template - name: Configure web-add template file for mail @@ -23,9 +25,11 @@ src: "{{ item }}" dest: "{{ evoadmin_scripts_dir }}/web-mail.tpl" force: "{{ evoadmin_mail_tpl_force }}" - with_first_found: - - "templates/evoadmin-web/web-mail.{{ inventory_hostname }}.tpl.j2" - - "templates/evoadmin-web/web-mail.{{ host_group }}.tpl.j2" - - "templates/evoadmin-web/web-mail.tpl.j2" - - "web-mail.tpl.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evoadmin-web/web-mail.{{ inventory_hostname }}.tpl.j2" + - "templates/evoadmin-web/web-mail.{{ host_group }}.tpl.j2" + - "templates/evoadmin-web/web-mail.tpl.j2" + - "templates/web-mail.tpl.j2" register: evoadmin_mail_tpl_template diff --git a/webapps/evoadmin-web/tasks/user.yml b/webapps/evoadmin-web/tasks/user.yml index 7b58270c..9c774f0d 100644 --- a/webapps/evoadmin-web/tasks/user.yml +++ b/webapps/evoadmin-web/tasks/user.yml @@ -112,9 +112,11 @@ mode: "0600" force: "{{ evoadmin_sudoers_conf_force }}" validate: "visudo -cf %s" - with_first_found: - - "templates/evoadmin-web/sudoers.{{ inventory_hostname }}.j2" - - "templates/evoadmin-web/sudoers.{{ host_group }}.j2" - - "templates/evoadmin-web/sudoers.j2" - - "sudoers.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evoadmin-web/sudoers.{{ inventory_hostname }}.j2" + - "templates/evoadmin-web/sudoers.{{ host_group }}.j2" + - "templates/evoadmin-web/sudoers.j2" + - "templates/sudoers.j2" register: evoadmin_sudoers_conf diff --git a/webapps/evoadmin-web/tasks/web.yml b/webapps/evoadmin-web/tasks/web.yml index cafccc72..251af4ea 100644 --- a/webapps/evoadmin-web/tasks/web.yml +++ b/webapps/evoadmin-web/tasks/web.yml @@ -32,11 +32,13 @@ src: "{{ item }}" dest: /etc/apache2/sites-available/evoadmin.conf force: "{{ evoadmin_force_vhost }}" - with_first_found: - - "templates/evoadmin-web/evoadmin.{{ inventory_hostname }}.conf.j2" - - "templates/evoadmin-web/evoadmin.{{ host_group }}.conf.j2" - - "templates/evoadmin-web/evoadmin.conf.j2" - - "evoadmin.conf.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evoadmin-web/evoadmin.{{ inventory_hostname }}.conf.j2" + - "templates/evoadmin-web/evoadmin.{{ host_group }}.conf.j2" + - "templates/evoadmin-web/evoadmin.conf.j2" + - "templates/evoadmin.conf.j2" register: evoadmin_vhost_template notify: reload apache2 @@ -62,11 +64,13 @@ owner: root group: www-data force: "{{ evoadmin_htpasswd_force }}" - with_first_found: - - "templates/evoadmin-web/htpasswd.{{ inventory_hostname }}.j2" - - "templates/evoadmin-web/htpasswd.{{ host_group }}.j2" - - "templates/evoadmin-web/htpasswd.j2" - - "htpasswd.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evoadmin-web/htpasswd.{{ inventory_hostname }}.j2" + - "templates/evoadmin-web/htpasswd.{{ host_group }}.j2" + - "templates/evoadmin-web/htpasswd.j2" + - "templates/htpasswd.j2" register: evoadmin_htpasswd_template when: evoadmin_htpasswd @@ -78,9 +82,11 @@ owner: evoadmin group: evoadmin force: "{{ evoadmin_config_local_php_force }}" - with_first_found: - - "templates/evoadmin-web/config.local.{{ inventory_hostname }}.php.j2" - - "templates/evoadmin-web/config.local.{{ host_group }}.php.j2" - - "templates/evoadmin-web/config.local.php.j2" - - "config.local.php.j2" + loop: "{{ query('first_found', templates) }}" + vars: + templates: + - "templates/evoadmin-web/config.local.{{ inventory_hostname }}.php.j2" + - "templates/evoadmin-web/config.local.{{ host_group }}.php.j2" + - "templates/evoadmin-web/config.local.php.j2" + - "templates/config.local.php.j2" register: evoadmin_config_local_php_template