title: Importing/adding a yum .repo file using Ansible
body: <p>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/<a href="https://docs.ansible.com/ansible/latest/modules/yum_repository_module.html" rel="noreferrer">yum_repository</a> modules.</p>
  
  <h2>Ansible</h2>
  
  <p>Here is my playbook:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>-
      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
  </code></pre>
  
  <p>I've tried all <code>include</code>, <code>metalink</code>, <code>baseurl</code>, and <code>mirrorlist</code> with no luck. Also I am missing the GPG key step, but I can't even get the repo added properly.</p>
  
  <p>The centos_o.repo file looks like this:</p>
  
  <pre><code># 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
  </code></pre>
  
  <h2>Shell</h2>
  
  <p>This is the shell script version that I am trying to convert to Ansible:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>If it makes any difference, I am running this with Vagrant's <a href="https://www.vagrantup.com/docs/provisioning/ansible_local.html" rel="noreferrer">Ansible local</a> provisioner on a CentOS box.</p>