Ansible - do-release-upgrade without prompts
Asked Answered
H

2

5

On Ubuntu I want to upgrade the OS with the command "do-release-upgrade" via Ansible, but it has prompts that can not be avoided.

Is there a way to use Ansible which answers the prompts to the user who runs the Ansible script?

We have several servers that can not be accessed with SSH, but with Ansible they can.

Servers are on Ubuntu 16.04 and all of servers need to be upgraded to Ubuntu 20.04.

In this process there are a lot of unavoidable prompts.

Hawfinch answered 9/12, 2021 at 0:7 Comment(2)
That is a very rambling question you have, without one iota of existing attempt, code you tried, errors you are receiving, or other things that would make it on topic for a programming site. However, in the spirit of being helpful, have you already tried expect:?Adrianadriana
Warning: It's better to avoid an in-place upgrade of the OS, especially from 16.04 to 20.04. A better practice would be to create a new VM next to the current one, and then install/configure the applications as they were on the old one. Also, since you only have SSH access via Ansible, you have no clue what's going on the VM itself. Again, it's strongly advised to not perform an in-place upgrade.Papen
P
8

Is there a way to use ansible playbook which will open possibility to answer on shell script prompt by user who runs ansible script?

You can use the expect module. Example:

- name: Upgrade Ubuntu w do release upgrade
  expect:
    command: do-release-upgrade
    responses:
      'First Question in the prompt' : 'y'
      'Second Question in the prompt' : 'y'

However, you want to execute the do-release-upgrade without prompts.

- shell: do-release-upgrade -f DistUpgradeViewNonInteractive

Please note:

  • Ensure to have a back-up and/or snapshot in place before upgrading
  • Ensure all packages are latest version
  • Ensure update-manager-core is installed
  • Ensure to reboot the machine after the do-release-upgrade

Also, please read my first comment. Since you do not have an SSH connection to the machine, it's really hard to debug and see what is going on if something went wrong.

Note that Ubuntu will leave logs by default at /var/log/dist-upgrade, use these to check/verify the upgrade. They provide a lot of help!

Papen answered 9/12, 2021 at 8:15 Comment(1)
I would've suggested the same solution: command: do-release-upgrade -f DistUpgradeViewNonInteractive. Good job.Pooley
H
0

This is a working solution for me.

This works for upgrade from Ubuntu 16 to Ubuntu 18 and Ubuntu 18 to Ubuntu 20

But the problem here is that if you miss one question server will be unreachable.

---
- name: Upgrading Software
  shell: echo "N N N N N N N N N N" | do-release-upgrade -f DistUpgradeViewNonInteractive

- name: Reboot the machine (Wait up to 10 min)
  include_tasks: /vagrant/ansible/roles/_handlers/reboot-and-reconect.yml
  when: reboot_and_reconnect == "y"

NOTE: Please be aware that all packages must be updated and upgraded before starting the release upgrade.

This is the walkaround solution when it is difficult to set a new server from scratch and then install required packages and other stuff.

Hawfinch answered 15/7, 2022 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.