-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable manual noble upgrade #7427
Open
legoktm
wants to merge
1
commit into
develop
Choose a base branch
from
stg-noble-playbook
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
install_files/ansible-base/roles/noble-migration/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
|
||
- name: Check host's migration state | ||
ansible.builtin.slurp: | ||
src: /etc/securedrop-noble-migration-state.json | ||
register: migration_json | ||
ignore_errors: yes | ||
|
||
- name: Skip migration if already done | ||
set_fact: | ||
already_finished: "{{ not migration_json.failed and (migration_json.content | b64decode | from_json)['finished'] == 'Done' }}" | ||
|
||
- name: Perform migration | ||
when: not already_finished | ||
block: | ||
- name: Instruct upgrade to begin | ||
ansible.builtin.copy: | ||
# It's okay to enable both app and mon here to simplify the logic, | ||
# as this only affects the server the file is updated on. | ||
content: | | ||
{ | ||
"app": {"enabled": true, "bucket": 5}, | ||
"mon": {"enabled": true, "bucket": 5} | ||
} | ||
dest: /usr/share/securedrop/noble-upgrade.json | ||
|
||
# Start the systemd service manually to avoid waiting for the timer to pick it up | ||
- name: Start upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
# Wait until we've finished the PendingUpdates stage. It's highly unlikely | ||
# we'll ever successfully complete this stage because as soon as the script | ||
# reaches finishes that stage, it reboots. Most likely this step will fail | ||
# as unreachable, which we ignore and wait_for_connection. | ||
- name: Wait for pending updates to be applied | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"PendingUpdates"' | ||
sleep: 1 | ||
timeout: 300 | ||
ignore_unreachable: yes | ||
ignore_errors: yes | ||
|
||
- name: Wait for the first reboot | ||
ansible.builtin.wait_for_connection: | ||
connect_timeout: 20 | ||
sleep: 5 | ||
delay: 10 | ||
timeout: 300 | ||
|
||
# Start the systemd service manually to avoid waiting for the timer to pick it up | ||
- name: Resume upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
- debug: | ||
msg: "The upgrade is in progress; it may take up to 30 minutes." | ||
|
||
# Same as above, this will most likely fail as unreachable when the server | ||
# actually reboots. | ||
- name: Wait for system upgrade to noble | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"Reboot"' | ||
sleep: 5 | ||
# Should finish in less than 30 minutes | ||
timeout: 1800 | ||
ignore_unreachable: yes | ||
ignore_errors: yes | ||
|
||
- name: Wait for the second reboot | ||
ansible.builtin.wait_for_connection: | ||
connect_timeout: 20 | ||
sleep: 5 | ||
delay: 10 | ||
timeout: 300 | ||
|
||
- name: Re-resume upgrade systemd service | ||
ansible.builtin.systemd: | ||
name: securedrop-noble-migration-upgrade | ||
state: started | ||
|
||
# This final check should actually succeed. | ||
- name: Wait for migration to complete | ||
ansible.builtin.wait_for: | ||
path: /etc/securedrop-noble-migration-state.json | ||
search_regex: '"finished":"Done"' | ||
sleep: 5 | ||
timeout: 300 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
- name: Disable OSSEC notifications | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
tasks: | ||
- name: Disable OSSEC notifications | ||
ansible.builtin.lineinfile: | ||
path: /var/ossec/etc/ossec.conf | ||
regexp: '<email_alert_level>7</email_alert_level>' | ||
line: '<email_alert_level>15</email_alert_level>' | ||
register: ossec_config | ||
|
||
- name: Restart OSSEC service | ||
ansible.builtin.systemd: | ||
name: ossec | ||
state: restarted | ||
when: ossec_config.changed | ||
become: yes | ||
|
||
# Upgrade app first, then mon. This is slower but more predictable; we only | ||
# need to verify a noble app can talk to a focal mon, and not the other way | ||
# around if the upgrade happens at different speeds. | ||
# Also it limits the damage if something goes wrong. | ||
- name: Perform upgrade on application server | ||
hosts: securedrop_application_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
roles: | ||
- role: noble-migration | ||
tags: noble-migration | ||
become: yes | ||
|
||
- name: Perform upgrade on monitor server | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
roles: | ||
- role: noble-migration | ||
tags: noble-migration | ||
become: yes | ||
legoktm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# This is not really necessary since the mon migration will restore the old | ||
# configuration back, but let's include it for completeness. | ||
- name: Restore OSSEC notifications | ||
hosts: securedrop_monitor_server | ||
max_fail_percentage: 0 | ||
any_errors_fatal: yes | ||
environment: | ||
LC_ALL: C | ||
tasks: | ||
- name: Re-enable OSSEC email alerts | ||
ansible.builtin.lineinfile: | ||
path: /var/ossec/etc/ossec.conf | ||
regexp: '<email_alert_level>(.*?)</email_alert_level>' | ||
line: '<email_alert_level>7</email_alert_level>' | ||
register: ossec_config | ||
|
||
- name: Restart OSSEC service | ||
ansible.builtin.systemd: | ||
name: ossec | ||
state: restarted | ||
when: ossec_config.changed | ||
become: yes |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the JSON check ever succeed if
migration.json_failed == True
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting for my own understanding: We don't just
set_fact
with the value offinished
here because later we'll useansible.builtin.wait_for
to wait/block until the server reaches the target state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we still need to verify the
ansible.builtin.slurp
step didn't fail, because it has ignore_errors: yes. Otherwise accessingmigration_json.content
will error.