Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafael Monnerat
slapos.package
Commits
1a01c455
Commit
1a01c455
authored
Sep 29, 2023
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playbook: add playbook reports in monitor app
parent
6a9c7891
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
113 additions
and
5 deletions
+113
-5
playbook/roles/ors/defaults/main.yml
playbook/roles/ors/defaults/main.yml
+1
-0
playbook/roles/ors/tasks/main.yml
playbook/roles/ors/tasks/main.yml
+36
-1
playbook/roles/ors/templates/playbook-report.j2
playbook/roles/ors/templates/playbook-report.j2
+8
-0
playbook/roles/upgrader/defaults/main.yml
playbook/roles/upgrader/defaults/main.yml
+1
-0
playbook/roles/upgrader/tasks/main.yml
playbook/roles/upgrader/tasks/main.yml
+64
-3
playbook/roles/upgrader/templates/playbook-report.j2
playbook/roles/upgrader/templates/playbook-report.j2
+1
-0
playbook/settings/ors.yml
playbook/settings/ors.yml
+1
-0
playbook/sha256sum
playbook/sha256sum
+1
-1
No files found.
playbook/roles/ors/defaults/main.yml
0 → 100644
View file @
1a01c455
playbook_report
:
False
playbook/roles/ors/tasks/main.yml
View file @
1a01c455
...
...
@@ -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
playbook/roles/ors/templates/playbook-report.j2
0 → 100644
View file @
1a01c455
{"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 -%}
}
playbook/roles/upgrader/defaults/main.yml
View file @
1a01c455
...
...
@@ -2,3 +2,4 @@ period_minute: '0'
period_hour
:
'
*/3'
extra_playbook
:
'
'
repeat_until_success
:
False
playbook_report
:
False
playbook/roles/upgrader/tasks/main.yml
View file @
1a01c455
---
-
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
playbook/roles/upgrader/templates/playbook-report.j2
0 → 100644
View file @
1a01c455
{"time": "{{ ansible_date_time['date'] }} {{ ansible_date_time['time'] }}", "log_level": "INFO", "message": "{{ playbook_report_message }}", "progress": "{{ playbook_report_progress }}"}
playbook/settings/ors.yml
View file @
1a01c455
...
...
@@ -2,3 +2,4 @@
install_folder
:
"
/opt/amarisoft"
amarisoft_version
:
"
2023-06-10"
launch_upgrader
:
True
playbook_report
:
True
playbook/sha256sum
View file @
1a01c455
d26ec3ea608b4bc23a525061b6081c30b86e1076faf45c35880d0568e8d1a00f
-
1a521af09daa0c44f0a03347c771a79871693df4f40902fe912469bd8af004f6
-
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment