--- # Guard and no-op paths of the mint entry point (nothing is installed). Each # failure case wraps the include in block/rescue, so the play passes when the # guard fires, and fails when the include returns or fails with another message. - name: Converge hosts: all gather_facts: false tasks: - name: Mint without confirmation block: - name: Include the mint entry point with gitea_mint_confirm unset ansible.builtin.include_role: name: mortis.kamino.gitea tasks_from: mint # Only reached when the include returned, so the guard did not fire. The message # must not contain the guard's text, so the rescue below cannot mistake it for it. - name: Fail because the include returned ansible.builtin.fail: msg: The include returned without the confirm guard firing rescue: - name: The confirm guard fired, and nothing else failed first ansible.builtin.assert: that: - "'mint is opt-in' in ansible_failed_result.msg" - "'gitea_mint_confirm=true' in ansible_failed_result.msg" quiet: true - name: Mint under each CI variable, run as a child process with only that one set delegate_to: localhost run_once: true ansible.builtin.command: argv: - ansible-playbook - -i - localhost, - "{{ playbook_dir }}/ci_guard.yml" environment: "{{ {'GITHUB_ACTIONS': '', 'GITEA_ACTIONS': '', 'CI': '', 'ANSIBLE_NOCOLOR': '1'} | combine({item: 'true'}) }}" loop: - GITHUB_ACTIONS - GITEA_ACTIONS - CI register: gitea_test_mint_ci # The child is expected to fail (the CI guard fires). Its rc and output are asserted in the next task. failed_when: false changed_when: false # Ansible 2.19 prints task failures to stderr, so both streams are checked. - name: The CI guard fired for every variable ansible.builtin.assert: that: - item.rc != 0 - "'refuses to run under CI' in (item.stdout ~ item.stderr)" - "'mint is opt-in' not in (item.stdout ~ item.stderr)" quiet: true loop: "{{ gitea_test_mint_ci.results }}" loop_control: label: "{{ item.item }}" - name: Mint outside CI with the token already defined, run as a child process delegate_to: localhost run_once: true ansible.builtin.command: argv: - ansible-playbook - -i - localhost, - "{{ playbook_dir }}/ci_guard.yml" - -e - gitea_api_token=molecule-not-a-token environment: GITHUB_ACTIONS: "" GITEA_ACTIONS: "" CI: "" ANSIBLE_NOCOLOR: "1" register: gitea_test_mint_noop # A child failure must not abort here; the next task asserts rc and output. failed_when: false changed_when: false - name: The mint was a no-op that registered no token fact ansible.builtin.assert: that: - gitea_test_mint_noop.rc == 0 - "'nothing to mint' in (gitea_test_mint_noop.stdout ~ gitea_test_mint_noop.stderr)" quiet: true # An empty token counts as missing (configure.yml refuses it), so the mint must not report # "nothing to mint". In check mode it creates nothing and registers no fact, and ends green # (ci_guard.yml asserts that gitea_minted_api_token is not defined). - name: Mint outside CI with an empty token in check mode, run as a child process delegate_to: localhost run_once: true ansible.builtin.command: argv: - ansible-playbook - -i - localhost, - "{{ playbook_dir }}/ci_guard.yml" - --check - -e - gitea_api_token= environment: GITHUB_ACTIONS: "" GITEA_ACTIONS: "" CI: "" ANSIBLE_NOCOLOR: "1" register: gitea_test_mint_empty # A child failure must not abort here; the next task asserts rc and output. failed_when: false changed_when: false - name: An empty token was treated as missing and nothing was minted ansible.builtin.assert: that: - gitea_test_mint_empty.rc == 0 - "'nothing to mint' not in (gitea_test_mint_empty.stdout ~ gitea_test_mint_empty.stderr)" quiet: true