I have a role which pushes updates to GitHub Enterprise. Every now and then the push fails, so I enclosed this push in a block/rescue with a rescue task to retry after a short random length pause. The result is success, mostly. However whenever the rescue task is triggered a later task in the playbook always fails and I’m scratching my head to understand why the later task fails.
The later task that fails is “Send success notification message via Email” and I’ve narrowed it down to the Jinja expression "{{ lookup('template','email_body_success.j2') }}"
. Both tasks are delegated to localhost. Other tasks that execute after the block/rescue also are delegated to localhost and they succeed.
Any ideas?
Playbook snippet:-
- block:
- name: "Push results back to https://{{ report_url.host }}/{{ report_url.org }}/{{ report_url.repo }}"
include_role:
name: role_cnd/repo
tasks_from: push
vars:
repo:
url: "git@{{ report_url.host }}:{{ report_url.org }}/{{ report_url.repo }}.git"
local_path: "{{ report_url.repo }}"
run_once: true
< snip snip >
- block:
- name: "Send success notification message via Email"
include_role:
name: role_cnd/notifications
tasks_from: email
vars:
email:
username: "{{ lookup('env','SMTP_USER') }}"
password: "{{ lookup('env','SMTP_PASS') }}"
subject: "{{ report_location | capitalize }} configuration compliance report in {{ dc_name }} // {{ stack }} on {{ host_pattern }}"
body: "{{ lookup('template','email_body_success.j2') }}"
to: "{{ tower_user_email }}"
run_once: True
Role tasks:-
push from role_cnd/repo
- block:
- name: "Push to GitHub"
shell: |
git pull
git add *
git commit -m "{{ ansible_play_name }}"
git push
args:
chdir: "{{ repo.local_path }}"
run_once: True
delegate_to: localhost
rescue:
- name: "Pause then retry push to GitHub"
pause:
seconds: "{{ 20 | random(start=3) }}"
run_once: True
- name: "Push to GitHub - 2nd attempt"
shell: |
git pull
git add *
git commit -m "{{ ansible_play_name }}"
git push
args:
chdir: "{{ repo.local_path }}"
run_once: True
delegate_to: localhost
email from role_cnd/notifications
- name: "Send notification message via email"
mail:
host: "{{ email.host | default('mail.example.com') }}"
port: "{{ email.port | default('587') }}"
secure: "{{ email.secure | default('starttls') }}"
username: "{{ email.username | default('') }}"
password: "{{ email.password | default('') }}"
subject: "{{ email.subject }}"
body: "{{ email.body }}"
from: "{{ email.from | default('email@example.com') }}"
to: "{{ email.to }}"
attach: "{{ email.attach | default([]) }}"
delegate_to: localhost
run_once: True