From 51aed4484455ca6a0183db848d6d26ea386bff5a Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sun, 28 Apr 2024 22:48:21 +0200 Subject: [PATCH] fix(pulumi/examples): use handlers --- .ansible-lint-ignore | 10 +++--- .../handlers/main.yml | 24 ++++++++++++++ .../tasks/configure/omnibus.yml | 32 ++----------------- .../tasks/install/omnibus.yml | 2 +- .../tasks/pre-flight.yml | 2 +- 5 files changed, 33 insertions(+), 37 deletions(-) create mode 100644 examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/handlers/main.yml diff --git a/.ansible-lint-ignore b/.ansible-lint-ignore index c0e09cf..6a66202 100644 --- a/.ansible-lint-ignore +++ b/.ansible-lint-ignore @@ -1,6 +1,4 @@ -ansible/playbooks/aws.ec2.enable-ssm-agent.yml package-latest -ansible/playbooks/keybase.register-device.yml no-changed-when -examples/ansible/aws_ec2.yml yaml[comments-indentation] -examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-playbook.yml package-latest -examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/configure/omnibus.yml no-handler -examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/pre-flight.yml name[template] \ No newline at end of file +ansible/playbooks/aws.ec2.enable-ssm-agent.yml package-latest +ansible/playbooks/keybase.register-device.yml no-changed-when +examples/ansible/aws_ec2.yml yaml[comments-indentation] +examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-playbook.yml package-latest diff --git a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/handlers/main.yml b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/handlers/main.yml new file mode 100644 index 0000000..414bb7b --- /dev/null +++ b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/handlers/main.yml @@ -0,0 +1,24 @@ +--- + +- name: "Validate Gitlab's configuration file" + become: true + ansible.builtin.command: >- + gitlab-ctl show-config + register: config_file_validation + changed_when: false + failed_when: config_file_validation.rc != 0 + +- name: Reconfigure Gitlab + when: config_file_validation is not failed + become: true + ansible.builtin.command: >- + gitlab-ctl reconfigure + register: reconfiguration + changed_when: + - reconfiguration.rc == 0 + - >- + ( + reconfiguration.stdout + | regex_findall('Infra Phase complete, .*') + ) is not search('0/') + failed_when: reconfiguration.rc != 0 diff --git a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/configure/omnibus.yml b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/configure/omnibus.yml index 9e4008e..7b09b76 100644 --- a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/configure/omnibus.yml +++ b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/configure/omnibus.yml @@ -10,32 +10,6 @@ mode: u=rw,g=,o= backup: true register: config_file - -- name: Validate the configuration file - # Since it cannot be validated by the 'template' module as it requires a file name to be specified. - when: config_file is changed - become: true - ansible.builtin.command: >- - gitlab-ctl show-config - register: config_file_validation - changed_when: false - failed_when: config_file_validation.rc != 0 - -- name: Reconfigure Gitlab - when: - - config_file is changed - - config_file_validation is not failed - become: true - ansible.builtin.command: >- - gitlab-ctl reconfigure - register: reconfiguration - changed_when: - - reconfiguration.rc == 0 - - >- - {{ - ( - reconfiguration.stdout - | regex_findall('Infra Phase complete, .*') - ) is not search('0/') - }} - failed_when: reconfiguration.rc != 0 + notify: + - "Validate Gitlab's configuration file" + - Reconfigure Gitlab diff --git a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/install/omnibus.yml b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/install/omnibus.yml index b4305e0..c1be69b 100644 --- a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/install/omnibus.yml +++ b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/install/omnibus.yml @@ -58,7 +58,7 @@ register: initial_password_file_stat - name: Recover the auto-generated administrator's initial password block: - - name: Read the initial password file + - name: Recover the password from the initial password file when: initial_password_file_stat.stat.exists block: - name: Read the initial password file diff --git a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/pre-flight.yml b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/pre-flight.yml index a1a2d39..efec87f 100644 --- a/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/pre-flight.yml +++ b/examples/pulumi/gitlab-omnibus-on-aws-ec2/ansible-role-gitlab-omnibus-on-ec2/tasks/pre-flight.yml @@ -38,7 +38,7 @@ - never ansible.builtin.debug: msg: "{{ query('community.dns.lookup', external_url_hostname) }}" - - name: Check an A or AAAA DNS record for '{{ external_url_hostname }}' exist + - name: Check an A or AAAA DNS record already exists for '{{ external_url_hostname }}' ansible.builtin.assert: that: >- query('community.dns.lookup', external_url_hostname) != [] or