Commit bb1070de authored by Joanne Hugé's avatar Joanne Hugé

playbook/bbu: add reporting to monitor SR

parent 574af5ef
......@@ -6,6 +6,7 @@
- upgrader_playbook: vifib-upgrade.yml
- extra_playbook: bbu.yml
- repeat_until_success: True
- playbook_report: True
vars_files:
- settings/vifib.yml
......
......@@ -6,6 +6,7 @@
- upgrader_playbook: vifib-upgrade.yml
- extra_playbook: ors.yml
- repeat_until_success: True
- playbook_report: True
vars_files:
- settings/vifib.yml
......
......@@ -2,3 +2,4 @@ period_minute: '0'
period_hour: '*/3'
extra_playbook: ''
repeat_until_success: False
playbook_report: False
......@@ -3,6 +3,28 @@
cron: name="Repeat until success" minute="*/5" hour="*" job="curl -fIs $(grep "^deb" /etc/apt/sources.list| cut -f2 -d' ' | head -n1) && flock -n /opt/upgrader/ansible.lock -c \"rm -rf /opt/upgrader/playbook && cp -R /opt/upgrader/playbook-tmp /opt/upgrader/playbook && cd /opt/upgrader/playbook && PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin ansible-playbook upgrader-run.yml --extra-vars 'extra_playbook={{ extra_playbook }} upgrader_playbook={{ upgrader_playbook }} repeat_until_success={{ repeat_until_success }} upgrade_kernel={{ upgrade_kernel | default(False) == True }}' -i hosts 2>>/opt/upgrader/latest_repeat_upgrade.log >> /opt/upgrader/latest_repeat_upgrade.log\""
when: repeat_until_success | bool
- name: Get monitor private directory path
shell: 'realpath $(dirname $(grep -lR "software_release_url = .*software/monitor/software.cfg" $(find /srv/slapgrid -type f -name "buildout.cfg")))/srv/monitor/private'
register: monitor_path
when: playbook_report | bool
- name: Create directory if it does not exist
file: path="{{ monitor_path.stdout }}/playbook-report" state=directory mode=0755
when: playbook_report | bool
- name: Setting playbook report message
set_fact: playbook_report_message="Starting upgrader playbook" playbook_report_progress="0"
- name: Render log template
template:
src: playbook-report.j2
dest: /tmp/playbook-report-tmp.log
when: playbook_report | bool
- name: Append to log
shell: 'cat /tmp/playbook-report-tmp.log >> {{ monitor_path.stdout }}/playbook-report/report.log'
when: playbook_report | bool
- file: path=/opt/upgrader state=directory mode=0755
- stat: path=/opt/upgrader/playbook
......@@ -67,12 +89,38 @@
register:
current_upgrade_signature
- name: Setting playbook report message
set_fact: playbook_report_message="Running upgrade" playbook_report_progress="10"
- name: Render log template
template:
src: playbook-report.j2
dest: /tmp/playbook-report-tmp.log
when: playbook_report | bool
- name: Append to log
shell: 'cat /tmp/playbook-report-tmp.log >> {{ monitor_path.stdout }}/playbook-report/report.log'
when: (playbook_report | bool) and (lookup('file', '/opt/upgrader/playbook-tmp/upgrade_after')|int > lookup('file', '/opt/upgrader/last-upgrade')|int ) and (lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature'))
- name: Do upgrade
shell: ansible-playbook {{ upgrader_playbook }} --extra-vars 'repeat_until_success={{ repeat_until_success }}' -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log
when: (lookup('file', '/opt/upgrader/playbook-tmp/upgrade_after')|int > lookup('file', '/opt/upgrader/last-upgrade')|int ) and (lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature'))
args:
chdir: /opt/upgrader/playbook-tmp/
- name: Setting playbook report message
set_fact: playbook_report_message="Running extra playbook" playbook_report_progress="60"
- name: Render log template
template:
src: playbook-report.j2
dest: /tmp/playbook-report-tmp.log
when: playbook_report | bool
- name: Append to log
shell: 'cat /tmp/playbook-report-tmp.log >> {{ monitor_path.stdout }}/playbook-report/report.log'
when: (playbook_report | bool) and (extra_playbook | length > 0)
- name: Do extra playbook
shell: ansible-playbook {{ extra_playbook }} --extra-vars 'launch_upgrader=False' -i hosts 2>>/opt/upgrader/latest_extra_playbook.log >> /opt/upgrader/latest_extra_playbook.log
when: extra_playbook | length > 0
......@@ -94,6 +142,19 @@
- include: remove-legacy.yml
- name: Setting playbook report message
set_fact: playbook_report_message="Successfully ran playbook" playbook_report_progress="100"
- name: Render log template
template:
src: playbook-report.j2
dest: /tmp/playbook-report-tmp.log
when: playbook_report | bool
- name: Append to log
shell: 'cat /tmp/playbook-report-tmp.log >> {{ monitor_path.stdout }}/playbook-report/report.log'
when: playbook_report | bool
- name: Remove cron after successful playbook run
cron: name="Repeat until success" state=absent
when: repeat_until_success | bool
......
{"time": "{{ ansible_date_time['date'] }} {{ ansible_date_time['time'] }}", "log_level": "INFO", "message": "{{ playbook_report_message }}", "progress": "{{ playbook_report_progress }}"}
6bd60d4d534e224e6eb8ed095ef0937dd490859b4db0470a9bc9cc947d3c1ce6 -
a5607f15135faed20570bf135a3fb9f2db8167f1463a58d302bbffcafb94a7e7 -
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment