From 6a31893ac8c0dce1d8aa011640bcdc67d3ed249e Mon Sep 17 00:00:00 2001 From: Sven Ketelsen Date: Wed, 10 May 2023 10:12:13 +0200 Subject: [PATCH] DEV-1028 extracted constraint checks into own task - ansible version - hetzner ansible roles --- awx.yml | 1 + create-database-backup.yml | 9 ++- create-database.yml | 9 ++- create-kibana-objects.yml | 9 ++- create-realm.yml | 9 ++- create-remote-database-backup.yml | 10 ++-- create-server.yml | 9 ++- create-service.yml | 9 ++- dump-hcloud-ips.yml | 10 ++-- evil-remove-server.yml | 11 ++-- export-database.yml | 11 ++-- hcloud_firewall.yml | 9 ++- import-database.yml | 9 ++- info.yml | 39 ------------- kubernetes.yml | 8 +-- kubespray | 2 +- mobene.yml | 1 + pmci-database-backup-create.yml | 9 ++- pmci-database-backup-import.yml | 9 ++- pmci-database-backup-restore.yml | 9 ++- pmci-inventory-cluster.yml | 9 ++- pmci-inventory-database.yml | 9 ++- provisioning.yml | 48 ++------------- remove-database.yml | 9 ++- remove-realm.yml | 9 ++- remove-server.yml | 9 ++- remove-service.yml | 9 ++- restore-database-backup.yml | 9 ++- restore-remote-database-backup.yml | 9 ++- setup-infrastructure-realm.yml | 7 +-- setup.yml | 94 ++---------------------------- smardigo.yml | 7 +-- tasks/constraints_check.yml | 54 +++++++++++++++++ update-docker-image.yml | 9 ++- update-monitoring.yml | 9 ++- update-service-state.yml | 9 ++- update-ssh-config-file.yml | 9 ++- upload-database-dumb.yml | 9 ++- 38 files changed, 189 insertions(+), 330 deletions(-) delete mode 100644 info.yml create mode 100644 tasks/constraints_check.yml diff --git a/awx.yml b/awx.yml index cdaffba..02e3098 100644 --- a/awx.yml +++ b/awx.yml @@ -19,6 +19,7 @@ - name: "Import autodiscover pre-tasks" import_tasks: tasks/autodiscover_pre_tasks.yml + become: false tags: - always diff --git a/create-database-backup.yml b/create-database-backup.yml index 2b5d1a9..ad65070 100644 --- a/create-database-backup.yml +++ b/create-database-backup.yml @@ -28,11 +28,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/create-database.yml b/create-database.yml index f139769..595acaf 100644 --- a/create-database.yml +++ b/create-database.yml @@ -34,11 +34,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/create-kibana-objects.yml b/create-kibana-objects.yml index eeec47b..5cf7e05 100644 --- a/create-kibana-objects.yml +++ b/create-kibana-objects.yml @@ -27,11 +27,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/create-realm.yml b/create-realm.yml index de38f07..158039c 100644 --- a/create-realm.yml +++ b/create-realm.yml @@ -28,11 +28,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/create-remote-database-backup.yml b/create-remote-database-backup.yml index cbb2cee..c78bc1a 100644 --- a/create-remote-database-backup.yml +++ b/create-remote-database-backup.yml @@ -26,11 +26,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" @@ -48,6 +47,7 @@ - "stage_{{ stage }}" - '{{ database_engine }}' changed_when: False + - name: "Add 'storage' servers to hosts if necessary" add_host: name: "{{ stage }}-backup-01" diff --git a/create-server.yml b/create-server.yml index b829d5f..ae9f651 100644 --- a/create-server.yml +++ b/create-server.yml @@ -21,11 +21,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/create-service.yml b/create-service.yml index 85d20fd..ea1ab14 100644 --- a/create-service.yml +++ b/create-service.yml @@ -22,11 +22,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/dump-hcloud-ips.yml b/dump-hcloud-ips.yml index 8bcb1af..7cdce79 100644 --- a/dump-hcloud-ips.yml +++ b/dump-hcloud-ips.yml @@ -19,12 +19,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least 2.10.x" - assert: - that: - - ansible_version.major >= 2 - - ansible_version.minor >= 10 - msg: "The ansible version has to be at least ({{ ansible_version.full }})" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # Add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/evil-remove-server.yml b/evil-remove-server.yml index 58f1a39..fdf6563 100644 --- a/evil-remove-server.yml +++ b/evil-remove-server.yml @@ -17,13 +17,10 @@ default: 'no' pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" - delegate_to: 127.0.0.1 - become: false + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always - name: "Import autodiscover pre-tasks" import_tasks: tasks/autodiscover_pre_tasks.yml diff --git a/export-database.yml b/export-database.yml index 1c4b002..4d0d156 100644 --- a/export-database.yml +++ b/export-database.yml @@ -24,11 +24,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" @@ -60,7 +59,7 @@ ansible_ssh_host: "{{ stage_server_domain }}" pre_tasks: - - name: "export autodiscover pre-tasks" + - name: "Import autodiscover pre-tasks" import_tasks: tasks/autodiscover_pre_tasks.yml become: false tags: diff --git a/hcloud_firewall.yml b/hcloud_firewall.yml index 46d24b4..39bd507 100644 --- a/hcloud_firewall.yml +++ b/hcloud_firewall.yml @@ -15,11 +15,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/import-database.yml b/import-database.yml index f076042..3997f72 100644 --- a/import-database.yml +++ b/import-database.yml @@ -24,11 +24,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/info.yml b/info.yml deleted file mode 100644 index 027dac0..0000000 --- a/info.yml +++ /dev/null @@ -1,39 +0,0 @@ ---- - -- name: 'apply setup to {{ host | default("all") }}' - hosts: '{{ host | default("all") }}' - serial: "{{ serial_number|default(25) }}" - become: false - - pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" - - - name: "Import autodiscover pre-tasks" - import_tasks: tasks/autodiscover_pre_tasks.yml - become: false - tags: - - always - - - name: "Variable " - debug: - msg: "{{ ansible_distribution }}" - delegate_to: 127.0.0.1 - - - name: "Variable " - debug: - msg: "{{ group_names }}" - delegate_to: 127.0.0.1 - - - name: "Printing ip addresses for {{ inventory_hostname }}" - debug: - msg: "{{ stage_server_ip }} / {{ stage_private_server_ip }}" - delegate_to: 127.0.0.1 - - - name: "Printing stage_server_infos" - debug: - msg: "{{ stage_server_infos }}" - delegate_to: 127.0.0.1 diff --git a/kubernetes.yml b/kubernetes.yml index e95683b..a8958f0 100644 --- a/kubernetes.yml +++ b/kubernetes.yml @@ -9,11 +9,8 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml tags: - always @@ -39,6 +36,7 @@ pre_tasks: - name: "Import autodiscover pre-tasks" import_tasks: tasks/autodiscover_pre_tasks.yml + become: false tags: - always diff --git a/kubespray b/kubespray index 00550ba..08467ad 160000 --- a/kubespray +++ b/kubespray @@ -1 +1 @@ -Subproject commit 00550ba832aa5d4f59bce03ead09d9e940e3a672 +Subproject commit 08467ad6b3bdd5b15c33e3a63d476630766bd04a diff --git a/mobene.yml b/mobene.yml index 41b8291..4e657ce 100644 --- a/mobene.yml +++ b/mobene.yml @@ -19,6 +19,7 @@ - name: "Import autodiscover pre-tasks" import_tasks: tasks/autodiscover_pre_tasks.yml + become: false tags: - always diff --git a/pmci-database-backup-create.yml b/pmci-database-backup-create.yml index 68a9802..0232989 100644 --- a/pmci-database-backup-create.yml +++ b/pmci-database-backup-create.yml @@ -24,11 +24,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/pmci-database-backup-import.yml b/pmci-database-backup-import.yml index be74020..9746eb8 100644 --- a/pmci-database-backup-import.yml +++ b/pmci-database-backup-import.yml @@ -24,11 +24,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/pmci-database-backup-restore.yml b/pmci-database-backup-restore.yml index e720047..6919105 100644 --- a/pmci-database-backup-restore.yml +++ b/pmci-database-backup-restore.yml @@ -27,11 +27,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/pmci-inventory-cluster.yml b/pmci-inventory-cluster.yml index cbf704a..f32a799 100644 --- a/pmci-inventory-cluster.yml +++ b/pmci-inventory-cluster.yml @@ -35,11 +35,10 @@ when: - data is defined - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/pmci-inventory-database.yml b/pmci-inventory-database.yml index a0a89ad..fca4474 100644 --- a/pmci-inventory-database.yml +++ b/pmci-inventory-database.yml @@ -22,11 +22,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/provisioning.yml b/provisioning.yml index 387f07d..eb2dfc2 100644 --- a/provisioning.yml +++ b/provisioning.yml @@ -1,50 +1,14 @@ --- -- name: 'apply setup to {{ host | default("all") }}' - hosts: '{{ host | default("all") }}' +- name: "apply setup to {{ host | default('all') }}" + hosts: "{{ host | default('all') }}" serial: "{{ serial_number | default(5) }}" - vars: - hetzner_ansible_dns_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-dns\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" - hetzner_ansible_hcloud_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-hcloud\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" gather_facts: no become: no pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" - tags: - - always - - - name: "get hetzner-ansible-dns version" - include_role: - name: hetzner-ansible-dns - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-dns version matches" - assert: - that: - - "'{{ hetzner_ansible_dns_version }}' in {{ hetzner_ansible_dns_current_version }}" - msg: "The current hetzner-ansible-dns version has to be {{ hetzner_ansible_dns_current_version }}" - tags: - - always - - - name: "get hetzner-ansible-hcloud version" - include_role: - name: hetzner-ansible-hcloud - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-hcloud version matches" - assert: - that: - - "'{{ hetzner_ansible_hcloud_version }}' in {{ hetzner_ansible_hcloud_current_version }}" - msg: "The current hetzner-ansible-dns version has to be {{ hetzner_ansible_hcloud_current_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml tags: - always @@ -52,8 +16,8 @@ uri: url: "https://api.hetzner.cloud/v1/firewalls" headers: - accept: application/json - authorization: Bearer {{ hetzner_authentication_ansible }} + accept: "application/json" + authorization: "Bearer {{ hetzner_authentication_ansible }}" return_content: yes register: hetzner_firewalls_response delegate_to: 127.0.0.1 diff --git a/remove-database.yml b/remove-database.yml index 6f60e1a..85f6fe3 100644 --- a/remove-database.yml +++ b/remove-database.yml @@ -26,11 +26,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/remove-realm.yml b/remove-realm.yml index 7cabb6e..e12eb83 100644 --- a/remove-realm.yml +++ b/remove-realm.yml @@ -28,11 +28,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/remove-server.yml b/remove-server.yml index 248ae3c..d3296aa 100644 --- a/remove-server.yml +++ b/remove-server.yml @@ -26,11 +26,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/remove-service.yml b/remove-service.yml index 2fc617d..9ba1d8e 100644 --- a/remove-service.yml +++ b/remove-service.yml @@ -22,11 +22,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/restore-database-backup.yml b/restore-database-backup.yml index 4b19f5e..d1edc74 100644 --- a/restore-database-backup.yml +++ b/restore-database-backup.yml @@ -27,11 +27,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/restore-remote-database-backup.yml b/restore-remote-database-backup.yml index 0b3463b..b974631 100644 --- a/restore-remote-database-backup.yml +++ b/restore-remote-database-backup.yml @@ -26,11 +26,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/setup-infrastructure-realm.yml b/setup-infrastructure-realm.yml index 3ecdf19..411d973 100644 --- a/setup-infrastructure-realm.yml +++ b/setup-infrastructure-realm.yml @@ -8,11 +8,8 @@ become: yes pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml tags: - always diff --git a/setup.yml b/setup.yml index 1120f97..ce8bed6 100644 --- a/setup.yml +++ b/setup.yml @@ -6,96 +6,18 @@ strategy: free vars: ansible_ssh_host: "{{ stage_server_domain }}" - hetzner_ansible_common_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-common\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" - hetzner_ansible_node_exporter_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-node-exporter\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" - hetzner_ansible_filebeat_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-filebeat\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" - hetzner_ansible_metricbeat_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-metricbeat\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" - hetzner_ansible_traefik_current_version: "{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+hetzner-ansible-traefik\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}" remote_user: root become: yes pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml tags: - always - - name: "get hetzner-ansible-common version" - include_role: - name: hetzner-ansible-common - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-common version matches" - assert: - that: - - "'{{ hetzner_ansible_common_version }}' in {{ hetzner_ansible_common_current_version }}" - msg: "The current hetzner-ansible-common version has to be {{ hetzner_ansible_common_current_version }}" - tags: - - always - - - name: "get hetzner-ansible-node-exporter version" - include_role: - name: hetzner-ansible-node-exporter - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-node-exporter version matches" - assert: - that: - - "'{{ hetzner_ansible_node_exporter_version }}' in {{ hetzner_ansible_node_exporter_current_version }}" - msg: "The current hetzner-ansible-node_exporter version has to be {{ hetzner_ansible_node_exporter_current_version }}" - tags: - - always - - - name: "get hetzner-ansible-filebeat version" - include_role: - name: hetzner-ansible-filebeat - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-filebeat version matches" - assert: - that: - - "'{{ hetzner_ansible_filebeat_version }}' in {{ hetzner_ansible_filebeat_current_version }}" - msg: "The current hetzner-ansible-filebeat version has to be {{ hetzner_ansible_filebeat_current_version }}" - tags: - - always - - - - name: "get hetzner-ansible-metricbeat version" - include_role: - name: hetzner-ansible-metricbeat - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-metricbeat version matches" - assert: - that: - - "'{{ hetzner_ansible_metricbeat_version }}' in {{ hetzner_ansible_metricbeat_current_version }}" - msg: "The current hetzner-ansible-metricbeat version has to be {{ hetzner_ansible_metricbeat_current_version }}" - tags: - - always - - - name: "get hetzner-ansible-traefik version" - include_role: - name: hetzner-ansible-traefik - tasks_from: _get_version.yml - tags: - - always - - - name: "Check if hetzner-ansible-traefik version matches" - assert: - that: - - "'{{ hetzner_ansible_traefik_version }}' in {{ hetzner_ansible_traefik_current_version }}" - msg: "The current hetzner-ansible-traefik version has to be {{ hetzner_ansible_traefik_current_version }}" + - name: "Import autodiscover pre-tasks" + import_tasks: tasks/autodiscover_pre_tasks.yml + become: false tags: - always @@ -118,12 +40,6 @@ - common - install - - name: "Import autodiscover pre-tasks" - import_tasks: tasks/autodiscover_pre_tasks.yml - become: false - tags: - - always - roles: - role: ansible-role-docker when: diff --git a/smardigo.yml b/smardigo.yml index 6da73e0..20d11d1 100644 --- a/smardigo.yml +++ b/smardigo.yml @@ -8,11 +8,8 @@ become: yes pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml tags: - always diff --git a/tasks/constraints_check.yml b/tasks/constraints_check.yml new file mode 100644 index 0000000..8b0cc34 --- /dev/null +++ b/tasks/constraints_check.yml @@ -0,0 +1,54 @@ +--- + +- name: "Check if ansible version is at least {{ ansible_minimal_version }}" + assert: + that: + - ansible_version.string is version(ansible_minimal_version, ">=") + msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + tags: + - always + +- name: "Reading all role versions and set versions as facts" + set_fact: + hetzner_ansible_roles: + - "hetzner-ansible-common" + - "hetzner-ansible-dns" + - "hetzner-ansible-filebeat" + - "hetzner-ansible-hcloud" + - "hetzner-ansible-metricbeat" + - "hetzner-ansible-node-exporter" + - "hetzner-ansible-traefik" + - "hetzner-ansible-sma-deploy" + tags: + - always + +- name: "Reading all role versions and set versions as facts (galaxy-requirements) " + set_fact: + {"{{ item | replace('-','_') }}_current_version":"{{ lookup('file', 'galaxy-requirements.yml') | regex_search('- name:\\s+' + item + '\\s+src:\\s+.*?\\s+scm:\\s+git\\s+version:\\s+(.*)', '\\1') }}"} + loop: "{{ hetzner_ansible_roles }}" + tags: + - always + +- name: "Reading all role versions and set versions as facts (role)" + include_role: + name: "{{ item }}" + tasks_from: _get_version.yml + loop: "{{ hetzner_ansible_roles }}" + tags: + - always + +- name: "Printing role versions" + debug: + msg: "<{{ item }}> : <{{ lookup('vars', item | replace('-','_') + '_current_version') }}> : <{{ lookup('vars', item | replace('-','_') + '_version') }}>" + loop: "{{ hetzner_ansible_roles }}" + tags: + - always + +- name: "Check role versions" + assert: + that: + - "'{{ lookup('vars', item | replace('-','_') + '_version') }}' in {{ lookup('vars', item | replace('-','_') + '_current_version') }}" + msg: "The current {{ item }} version has to be {{ lookup('vars', item | replace('-','_') + '_current_version') }}" + loop: "{{ hetzner_ansible_roles }}" + tags: + - always diff --git a/update-docker-image.yml b/update-docker-image.yml index d2d5726..7e9155b 100644 --- a/update-docker-image.yml +++ b/update-docker-image.yml @@ -23,11 +23,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/update-monitoring.yml b/update-monitoring.yml index 1a2a040..5f12978 100644 --- a/update-monitoring.yml +++ b/update-monitoring.yml @@ -19,11 +19,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/update-service-state.yml b/update-service-state.yml index 4fc14f6..87c9c0e 100644 --- a/update-service-state.yml +++ b/update-service-state.yml @@ -21,11 +21,10 @@ connection: local pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/update-ssh-config-file.yml b/update-ssh-config-file.yml index ff5a715..cf36563 100644 --- a/update-ssh-config-file.yml +++ b/update-ssh-config-file.yml @@ -14,11 +14,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always # add virtual server to load stage specific variables as context - name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts" diff --git a/upload-database-dumb.yml b/upload-database-dumb.yml index 2a91af0..0a7e619 100644 --- a/upload-database-dumb.yml +++ b/upload-database-dumb.yml @@ -23,11 +23,10 @@ gather_facts: false pre_tasks: - - name: "Check if ansible version is at least {{ ansible_minimal_version }}" - assert: - that: - - ansible_version.string is version(ansible_minimal_version, ">=") - msg: "The ansible version has to be at least {{ ansible_minimal_version }}" + - name: "Import constraints check" + import_tasks: tasks/constraints_check.yml + tags: + - always tasks: - name: "Add maria servers to hosts if necessary"