4

Here we are trying to start auto updating packages in Ubuntu through Ansible playbook.

dpkg-reconfigure -plow unattended-upgrades

When we run this command manually, it shows the following prompt, and it starts updating packages :-

 Configuring unattended-upgrades 

                                                      

Applying updates on a frequent basis is an important part of keeping
systems secure. By default, updates need to be applied manually using
package management tools.
Alternatively, you can choose to have this system automatically download and install important updates.

Automatically download and install stable updates?

                  <Yes>                       <No> 

But running this command with Ansible it stopped at this step How we can skip this prompt while running this command with Ansible playbook.
Playbook code is following:- ansible-code for updating Ubuntu packages

Mohamed Slama
  • 1,841
  • 1
  • 16
  • 37
karan
  • 41
  • 1
  • 2

1 Answers1

8

Here's how I set up unattended-upgrades using Ansible.

- name: echo "unattended-upgrades unattended-upgrades/enable_auto_updates boolean true" | sudo debconf-set-selections  - auto install security updates
  debconf: 
    name: unattended-upgrades 
    question: unattended-upgrades/enable_auto_updates 
    vtype: boolean 
    value: 'true'

- name: apt install unattended-upgrades
  apt: 
    name: unattended-upgrades
     
- name: dpkg-reconfigure -f noninteractive unattended-upgrades
  command:
    cmd: dpkg-reconfigure -f noninteractive unattended-upgrades
    creates: /etc/apt/apt.conf.d/20auto-upgrades
Hrafn
  • 232
  • 1
  • 13
Collin Anderson
  • 3,166
  • 1
  • 17
  • 12
  • Why does the debconf have an echo as it's name? – Cwista Feb 13 '23 at 00:23
  • @Ecker00 My guess would be that Collin likes to have the names of each step be the shell commands that would accomplish the same effect as the step in question. – Hrafn Jul 23 '23 at 14:15