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/yum_repository modules.
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
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.
The first task you're telling the system to only update the yum cache. On the second you are effectively upgrading all packages to the latest version by using state=latest but you should also use update_cache=yes on the same task to be sure you're refreshing the cache with its latest package information.
Ansible's yum module is used to manage packages with the yum package manager, which is the default on Red Hat based Linux distributions such as Red Hat Enterprise Linux and CentOS. Most systems require root/superuser permissions to manage packages, which means that become: true is required.
To enable all repositories run "yum-config-manager --enable \*". --disable Disable the specified repos (automatically saves). To disable all repositories run "yum-config-manager --disable \*". --add-repo=ADDREPO Add (and enable) the repo from the specified file or url.
Use the shell command with the creates flag. That will skip the step if the repo file exists. You'll need to make sure you know what the repo file is called.
- name: Add CentOS_o repository
shell: yum-config-manager --add-repo=http://example.net/mirror/centos_o.repo
args:
creates: /etc/yum.repos.d/centos_o.repo
If you need to add any architecture to the url use something like
- name: Add CentOS_7_speciality repository
shell: yum-config-manager --add-repo=http://example.net/{{ ansible_distribution | lower }}/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
centos_o.repo
args:
creates: /etc/yum.repos.d/centos_o.repo
Ansible will replace the variables with
{{ ansible_distribution | lower }} == centos
{{ ansible_distribution_major_version }} == 7
{{ ansible_architecture }} == x86_64
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With