Commit 1a01c455 authored by Joanne Hugé's avatar Joanne Hugé

playbook: add playbook reports in monitor app

parent 6a9c7891
......@@ -3,6 +3,41 @@
- name: Create /opt/upgrader where some logs will be stored
file: path=/opt/upgrader state=directory mode=0755
- 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: Check Amarisoft version
shell: 'find /opt/amarisoft -maxdepth 1 | grep "^/opt/amarisoft/v[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$" | cut -d/ -f4 | sort | tail -n1'
register: amarisoft_version
ignore_errors: yes
- name: Check registry URL
shell: "grep registry /etc/re6stnet/re6stnet.conf | awk '{ print $2; }'"
register: registry_url
ignore_errors: yes
- name: Setting playbook report message
set_fact:
playbook_report_message: "Starting ors playbook"
playbook_report_progress: "30"
data: { 'registry_url': "{{ registry_url.stdout }}", 'amarisoft_version': "{{ amarisoft_version.stdout }}"}
- 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)
# SSD image backports
- stat: path=/opt/upgrader/last-backport
......@@ -137,5 +172,5 @@
# Schedule and upgrade playbook
- name: Install upgrader
shell: 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_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log
shell: 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 }} playbook_report={{ playbook_report }}' -i hosts 2>>/opt/upgrader/latest_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log
when: launch_upgrader | bool
{"time": "{{ ansible_date_time['date'] }} {{ ansible_date_time['time'] }}", "log_level": "INFO", "message": "{{ playbook_report_message }}", "progress": "{{ playbook_report_progress }}"
{%- if 'registry_url' in data -%}
, "registry_url": "{{ data['registry_url'] }}"
{%- endif -%}
{%- if 'amarisoft_version' in data -%}
, "amarisoft_version": "{{ data['amarisoft_version'] }}"
{%- endif -%}
}
......@@ -2,3 +2,4 @@ period_minute: '0'
period_hour: '*/3'
extra_playbook: ''
repeat_until_success: False
playbook_report: False
---
- name: Set Cron to repeat until success
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\""
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 }} playbook_report={{ playbook_report }}' -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="20"
- 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
......@@ -80,7 +128,7 @@
chdir: /opt/upgrader/playbook-tmp/
- name: Set Cron
cron: name="Launch Upgrader with ansible" minute="{{ period_minute }}" hour="{{ period_hour }}" job="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 'period_minute={{ period_minute }} period_hour={{ period_hour }} upgrader_playbook={{ upgrader_playbook }} upgrade_kernel={{ upgrade_kernel | default(False) == True }}' -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log\""
cron: name="Launch Upgrader with ansible" minute="{{ period_minute }}" hour="{{ period_hour }}" job="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 'period_minute={{ period_minute }} period_hour={{ period_hour }} upgrader_playbook={{ upgrader_playbook }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report }}' -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log\""
when: repeat_until_success | bool == False
- cron: name="Launch Upgrader" state=absent
......@@ -94,10 +142,23 @@
- 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
- name: Set Anacron after successful playbook run
lineinfile: dest=/etc/anacrontab regexp="^[0-9]+ [0-9]+ extra.playbook (.*)" line="1 10 extra.playbook 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_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log\"" state=present
lineinfile: dest=/etc/anacrontab regexp="^[0-9]+ [0-9]+ extra.playbook (.*)" line="1 10 extra.playbook 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 }} playbook_report={{ playbook_report }}' -i hosts 2>>/opt/upgrader/latest_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log\"" state=present
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 }}"}
......@@ -2,3 +2,4 @@
install_folder: "/opt/amarisoft"
amarisoft_version: "2023-06-10"
launch_upgrader: True
playbook_report: True
d26ec3ea608b4bc23a525061b6081c30b86e1076faf45c35880d0568e8d1a00f -
1a521af09daa0c44f0a03347c771a79871693df4f40902fe912469bd8af004f6 -
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