'FAILED! => {"changed": false, "msg": "apt cache update failed"} when trying to

I am new to Ansible and try, as an example, a task to install Vivaldi. My only task in a role Vivaldi update starts with

    - name: Run apt upgrade
      apt:
        upgrade: "yes"
        update_cache: yes
        cache_valid_time: 432000

    - name: Add Vivaldi Repository
      apt_repository:
          repo: "deb https://repo.vivaldi.com/stable/deb/ stable main"
          state: present
          filename: vivaldi.list
          update_cache: true
      tags:
         - vivaldi

And with this, I fail on localhost on a Debian 10 (Buster) installation:

Linux london 4.19.0-12-amd64 #1 SMP Debian 4.19.152-1 (2020-10-18) x86_64 GNU/Linux).

All commands succeed on the command line.

Ansible is 2.9.15.

The first task runs OK (if run alone), but the second fails with:

FAILED! => {"changed": false, "msg": "apt cache update failed"}.

A task to add a repository key fails with:

FAILED! => {"changed": false, "id": "6D3789EDC3401E12", "msg": "key does not seem to have been added"}

However, if I add the repository manually to /etc/apt/sources.list the last task,

    - name: Install Vivaldi
      apt:
          name: vivaldi-stable
          update_cache: yes
          state: latest
      tags:
         - vivaldi

it succeeds.

What am I doing wrong?



Solution 1:[1]

According to official documentation you need to add the key and later the repository:

Manual setup of the Vivaldi Linux repositories

Edit your playbook with the task Add key:

- name: Run apt upgrade
  apt:
    upgrade: "yes"
    update_cache: yes
    cache_valid_time: 432000

- name: Add key
  apt_key:
    url: https://repo.vivaldi.com/archive/linux_signing_key.pub
    state: present
  tags:
     - vivaldi

- name: Add Vivaldi Repository
  apt_repository:
      repo: "deb https://repo.vivaldi.com/stable/deb/ stable main"
      state: present
      filename: vivaldi.list
      update_cache: true
  tags:
     - vivaldi

- name: Install Vivaldi
  apt:
      name: vivaldi-stable
      update_cache: yes
      state: latest
  tags:
     - vivaldi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Mortensen