yum_repository module fails properly insert *repo configuration file - ansible

there, I am having an issue if anybody had encountered and solved it, please share your knowledge.
Machine:
CentOS Linux release 7.6.1810 (Core)
NAME="CentOS Linux"
epel.yml
- name: Add repository
yum_repository:
name: epel
description: epel-repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
ansible-playbook epel.yml (I have removed not necessary part of the epel.yml)
Above, code when run successfully enters epel.repo in /etc/yum.repos.d/ folder. However, when I try to install any package it gives me en error referring "Failed to connect. Network is unreachable"
I have checked #cat /etc/yum.repos.d/epel.repo
baseurl=https://download.fedoraproject.org/pub/epel///
I searched for where $releasever adn $basearch variables come from? Not very concrete answers around.
Please help.

It seems like yum couldn't determine $releasever and $basearch. Check this post for the possible reasons why this wasn't possible.
To workaround the problem, you could try using the yum module instead:
- name: install the latest version of epel
yum:
name: epel-release
state: latest
Or install it directly from the rpm package:
- name: install from url
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
state: present

Related

Yum module is choosing rpm with wrong os release with "latest" option

Suppose I have the following ansible yum task
- name: install java-1.8.0
yum:
name: java-1.8.0-openjdk
state: latest
Now, yum repo, is not the standard java repo, but local repo on site premises. Differently from standard ones, it contains java packages rpms for different architecture and os release in the same directory.
The behavior that we see is that this task tries to install java for centos8 on centos7 disregarding the architecture that it runs on.
for example instead of
java-1.8.0-openjdk-....el7_5.x86_64.rpm
it will take
java-1.8.0-openjdk-....el8_4.x86_64.rpm
though it running on el7
Is this desired behavior for this ansible yum module when running "latest" or is it bug?

How to pass options to dnf when using Ansible

When installing packages through the Ansible's dnf module. How do I pass options like --nobest to dnf? Is there alternative to using raw shell commands.
I had similar problem (but i'm using yum package manager) and figured a work around here
The issue is that docker-ce has not been packaged for CentOS 8 yet.
An ugly workaround is to install containerd.io manually beforehand:
pre_tasks:
- yum:
name: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
So, try to set full package url as package name and it should definitely work.
nobest can be passed as a parameter while using the DNF module in the playbook
You can refer here dnf_module for other options/parameters that can be passed to the dnf ansible module
For example :
- name: Install the latest version of Apache from the testing repo
dnf:
name: httpd
enablerepo: testing
state: present
- name: Install the latest version of Apache
dnf:
name: httpd
state: present
nobest: false

No package matching 'maven' found available, installed or updated.

When i use yum module in an ansible playbook to install maven on the target server, i get this error message: No package matching 'maven' found available, installed or updated
But when i log on to the target server, i could successfully install maven with yum install maven
Not sure what is wrong with the playbook. Where should i look for any further logs or how to resolve this issue?
playbook task looks like:
- name: install maven (and other packages if needed)
yum: name=maven state=latest
become: true
Oh, I found that yum module doesn't update cache by default, but rpm (on command line) does.
Try to add update_cache: yes to yum module parameters.

I can no longer install software using a list of items

I can no longer install software using a list of items.
I've commented out git to see if it was the issue. It turns out nano will fail too.
My task:
- name: Install git, nano, curl, wget, unzip and mercurial
apt: name={{item}} state=installed
with_items:
# - git
- nano
- curl
- wget
- unzip
- mercurial
The error:
TASK [common : Install git, nano, curl, wget, unzip and mercurial] *************
failed: [local_vm] (item=[u'nano', u'curl', u'wget', u'unzip', u'mercurial']) => {"failed": true, "item": ["nano", "curl", "wget", "unzip", "mercurial"], "msg": "No package(s) matching '['nano'' available"}
A stab in the dark would be extra quotes perhaps?
From the console of my server:
me#server:~$ sudo apt-get install nano
Reading package lists... Done
Building dependency tree
Reading state information... Done
nano is already the newest version (2.5.3-2ubuntu2)
I'm running Ansible 2.2.0
Update #1
Python 2.7.6 on client, Python 2.7.12 on server.
Update #2
Either I got betrayed by the Windows Linux Subsystem or Ansible 2.2.0 is the issue. I tried on another VM (CentOS 7) where Ansible 2.3 is installed and the same script went through fine.
The problem is with items squashing for package modules.
If you can't update Ansible version, use ANSIBLE_SQUASH_ACTIONS=[] environment variables as a workaround.
It will increase execution time for apt module (because it will be executed for every item separately), but will not try to join items into single call.

Is it safe to use ansible's package module to upgrade all packages?

I have a numer of ansible playbooks I use to perform certain actions on Debian and CentOS VMs. Until now, when I needed to handle packages I would use ansible modules apt and yum. Consequently, I had to check which OS was installed and then use the correct ansible module.
However, I've recently learned there's a module called package which somehow unifies package managers, reducing playbook's complexity, so I'm now trying to use this module only.
One of the operations I want to perform is to update all packages. The problem is that ansible's documentation doesn't say how to do this using package. It does say, however, how to do it with apt and yum: the first one uses and upgrade operation and the latter suggests writing something like:
yum: name=* state=latest
For this reason I thought I could use package to do the following:
package: name=* state=latest
When I ran this playbook I didn't come across any error but this isn't documented anywhere and apt and yum don't work exactly the same way. So my question is: is the command above a safe one as in does it actually do what I want it to do?
Thanks in advance!
EDIT:
I have found out that using package: name=* state=latest will try to install or update all available packages instead of just updating installed ones. Therefore this isn't a valid solution for me. Alternatively, I can keep using yum and apt for this particular action, but I do wonder why is it not possible to do this using package, or if I'm missing something.
Well after further testing I can now answer the question by myself, and the answer is no. Using package: name=* state=latest on a Debian machine will try to install or update every package available in the repositories, so it can't be used as a replacement for an apt-get upgrade.
From the docs below i think its clear that the use you are describing can be considered safe.
From package documentation:
This module actually calls the pertinent package modules for each system (apt, yum, etc).
So whatever you pass to it should be supported by the underlined packagers yum or apt.
From apt documentation:
Name wildcards (fnmatch) like apt* and version wildcards like foo=1.0* are also supported.
From yum->name documentation:
When using state=latest, this can be '*' which means run: yum -y update.
EDIT: After #Xavier Alvarez testing the apt: name=* state=latest will install all packages in repo.

Resources