I have some servers that are on Ubuntu 22.04. I’m very much an amateur when it comes to Ansible.
So far (using playbooks found online), I was able to automate the updates and reboots of the servers. But each time they reboot, I need to enter the bootloader password for them to finish rebooting.
Is there any way I can also have Ansible enter the bootloader username and password? Because technically I can’t SSH into the servers as long as the password hasn’t been entered so I don’t see how Ansible would be able to either.
This is the playbook I use if needed at all:
- name: Update and, if necessary, reboot Ubuntu servers
hosts: ubuntu
become: true
become_user: root
tasks:
- name: Ping my hosts
ansible.builtin.ping:
tags:
- ping
- name: Update apt repo and cache on all Ubuntu boxes
ansible.builtin.apt:
update_cache: yes
force_apt_get: yes
cache_valid_time: 3600
- name: update apt list
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
- name: Upgrade all packages on servers
ansible.builtin.apt:
upgrade: dist
force_apt_get: yes
- name: Check if reboot is needed on all servers
register: reboot_required_file
ansible.builtin.stat:
path: /var/run/reboot-required
get_checksum: false
- name: Reboot (if required)
when: reboot_required_file.stat.exists
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible for updates"
connect_timeout: 5
reboot_timeout: 300
pre_reboot_delay: 0
post_reboot_delay: 30
test_command: uptime