Closed DavidGL17 closed 2 years ago
What is the error?
Using shell
is not the best idea, since Ansible has specialized modules for adding repositories and installing packages
when trying to install the package with apt it does not find it in the available packages.
I ran into a similar issue using the role as reference. Here's an example of the exact error.
TASK [system : Install CrowdSec and iptables bouncer] ************************************************************************************************
fatal: [myhost]: FAILED! => {"changed": false, "msg": "No package matching 'crowdsec' is available"}
When running apt update
on the host, I would get these warnings too.
W: Skipping acquire of configured file 'stable/binary-amd64/Packages' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/i18n/Translation-en_GB' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/i18n/Translation-en' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/cnf/Commands-amd64' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
I understand we need to use 'main' instead of 'stable', I was able to resolve my issue with the following task definition for adding the apt repository.
- name: Add CrowdSec apt repository
apt_repository:
repo: deb https://packagecloud.io/crowdsec/crowdsec/{{ansible_lsb['id']|lower}} {{ansible_lsb['codename']}} main
state: present
@DavidGL17 @dannycjones Please re-test with the latest version
I tried with the following tasks, but no luck:
- name: Add CrowdSec GPG apt Key
apt_key:
url: https://packagecloud.io/crowdsec/crowdsec/gpgkey
state: present
- name: Add CrowdSec apt repository
apt_repository:
repo: deb [arch=amd64] https://packagecloud.io/crowdsec/crowdsec/ubuntu focal stable
state: present
- name: Install CrowdSec and iptables bouncer
apt:
name:
- crowdsec
state: present
TASK [system : Install CrowdSec and iptables bouncer] ************************************************************************************************
fatal: [myhost]: FAILED! => {"cache_update_time": 1646683493, "cache_updated": false, "changed": false, "msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" install 'crowdsec'' failed: E: Package 'crowdsec' has no installation candidate\n", "rc": 100, "stderr": "E: Package 'crowdsec' has no installation candidate\n", "stderr_lines": ["E: Package 'crowdsec' has no installation candidate"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nPackage crowdsec is not available, but is referred to by another package.\nThis may mean that the package is missing, has been obsoleted, or\nis only available from another source\n\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...", "Package crowdsec is not available, but is referred to by another package.", "This may mean that the package is missing, has been obsoleted, or", "is only available from another source", ""]}
Note full output for apt sources and apt update
:
$ cat /etc/apt/sources.list /etc/apt/sources.list.d/* | grep -v "^#" | grep .
deb http://gb.archive.ubuntu.com/ubuntu focal main restricted
deb http://gb.archive.ubuntu.com/ubuntu focal-updates main restricted
deb http://gb.archive.ubuntu.com/ubuntu focal universe
deb http://gb.archive.ubuntu.com/ubuntu focal-updates universe
deb http://gb.archive.ubuntu.com/ubuntu focal multiverse
deb http://gb.archive.ubuntu.com/ubuntu focal-updates multiverse
deb http://gb.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
deb http://gb.archive.ubuntu.com/ubuntu focal-security main restricted
deb http://gb.archive.ubuntu.com/ubuntu focal-security universe
deb http://gb.archive.ubuntu.com/ubuntu focal-security multiverse
deb https://download.docker.com/linux/ubuntu focal stable
deb [arch=amd64] https://packagecloud.io/crowdsec/crowdsec/ubuntu focal stable
$ sudo apt update
Hit:1 http://gb.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://gb.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://gb.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://gb.archive.ubuntu.com/ubuntu focal-security InRelease
Hit:5 https://download.docker.com/linux/ubuntu focal InRelease
Hit:6 https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
W: Skipping acquire of configured file 'stable/binary-amd64/Packages' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/i18n/Translation-en_GB' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/i18n/Translation-en' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
W: Skipping acquire of configured file 'stable/cnf/Commands-amd64' as repository 'https://packagecloud.io/crowdsec/crowdsec/ubuntu focal InRelease' doesn't have the component 'stable' (component misspelt in sources.list?)
If I switch from 'stable' component to 'main' component, issue goes away and installation is successful.
- name: Add CrowdSec apt repository
apt_repository:
repo: deb [arch=amd64] https://packagecloud.io/crowdsec/crowdsec/ubuntu focal main
state: present
In the CrowdSec deb installation guide, they are using 'main' component.
(installing on an Ubuntu server 20.04) Hey, i am trying to adapt your playbook to my usage and during my exploration of every role, found an error during the installation of crowdsec.
These two tasks do not allow for crowdsec to be installed with apt (with the next task in the file). I tried a bit on my side, and found this workaround :
This task fixes the issue and allows to install crowdsec.
(BTW, ty very much for this repository and your videos, you have given me a nice objective to work for as i try to create my own private server. Hope this will help!)