Issue
I'm trying to install MariaDB (or any software) from a custom repository using Ansible but I am not sure how to import the .repo file using the yum/href="https://docs.ansible.com/ansible/latest/modules/yum_repository_module.html" rel="noreferrer">yum_repository modules.
Ansible
Here is my playbook:
-
hosts: all
become: true
remote_user: root
tasks:
-
name: set system timezone
timezone:
name: America/Toronto
-
name: add custom repository
yum_repository:
name: centos_o
description: custom repositories
baseurl: http://example.net/mirror/centos_o.repo
-
name: ensure mariadb is installed
yum:
name: mariadb-server-5.5.*
state: installed
I've tried all include
, metalink
, baseurl
, and mirrorlist
with no luck. Also I am missing the GPG key step, but I can't even get the repo added properly.
The centos_o.repo file looks like this:
# JENKINS
[jenkins]
name=CentOS-$releasever - JENKINS
baseurl=http://example.net/mirror/jenkins/
enabled=0
gpgcheck=1
# MariaDB 5.5
[mariadb]
name=CentOS-$releasever - MariaDB
baseurl=http://example.net/mirror/mariadb/yum/5.5/centos$releasever-amd64/
enabled=0
gpgcheck=1
# MariaDB 10.0
[mariadb]
name=CentOS-$releasever - MariaDB
baseurl=http://example.net/mirror/mariadb/yum/10.0/centos$releasever-amd64/
enabled=0
gpgcheck=1
Shell
This is the shell script version that I am trying to convert to Ansible:
yum clean all
yum-config-manager --add-repo=http://example.net/mirror/centos_o.repo
yum-config-manager --enable mariadb
rpm --import http://example.net/mirror/mariadb/RPM-GPG-KEY-MariaDB
If it makes any difference, I am running this with Vagrant's Ansible local provisioner on a CentOS box.
Solution
It appears that you are correct, they don't offer what you are after. Their model is such that you would call yum_repository:
3 times, once with each of the baseurl=
values you already have in your .repo
file.
Thus, given your circumstance, I'd recommend just using command:
to run the yum-config-manager --add-repo
just as you are in shell. The only catch to that would be if yum-config-manager --add-repo=
isn't idempotent, in which case you'd have to guard that command:
by hand to keep it from adding that same repo file over and over with each run.
Answered By - mdaniel Answer Checked By - Willingham (WPSolving Volunteer)