# Can't get playbooks to work for creating yum repositories

**URL:** <https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199>\
**Category:** Ansible Project\
**Created:** [July 30, 2018, 5:32pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199 "2018-07-30T17:32:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Greene](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Paul\_Greene](https://forum.ansible.com/u/Paul_Greene)\
**Post date:** [July 30, 2018, 5:32pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199/1 "2018-07-30T17:32:37Z")

</div>

I want to automate yum repository configuration using an ansible playbook. For the most part, these systems won’t have internet access and need to access an internal yum repository.

I initially copied the content of a yum playbook from this link - [https://docs.ansible.com/ansible/2.5/modules/yum\_repository\_module.html](https://docs.ansible.com/ansible/2.5/modules/yum_repository_module.html)

and copied this content:

```auto
- name: Add repository
  yum_repository:
    name: epel
    description: EPEL YUM repo
    baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/

I added the leading

--- 
- hosts: client01,

And ended up with this (baseurl modified to internal yum server) - other edits based on error messages I was getting

---
- hosts: client01
  tasks:
   - name: Add repository
      yum_repository:
       name: epel
       description: EPEL YUM repo
       baseurl: http://10.0.0.1/CentOS7-EPEL

I'm getting this error now, and not sure where to go with it from here.

[admin@kickstart ansible]$ ansible-playbook repo-playbook3.yml 
ERROR! Syntax Error while loading YAML.
  mapping values are not allowed in this context

The error appears to have been in '/etc/ansible/repo-playbook3.yml': line 5, column 21, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

   - name: Add repository
      yum_repository:
                    ^ here

(I should add that I'm new to ansible and am a little fuzzy on if this kind of thing is more appropriate for a playbook or a role.)

PG

```

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 30, 2018, 5:34pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199/2 "2018-07-30T17:34:15Z")

</div>

You have an indentation error in the following:

- name: Add repository  
yum\_repository:

`yum_repository` should be indented to the same level as `name`:

- name: Add repository  
yum\_repository:

---

<div class="post-metadata">

**Author:** ![Paul\_Greene](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Paul\_Greene](https://forum.ansible.com/u/Paul_Greene)\
**Post date:** [July 30, 2018, 5:59pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199/3 "2018-07-30T17:59:52Z")

</div>

I think that might have fixed the immediate problem (I get the impression ansible is quite picky about indentation mistakes!), but I’m getting this new error:

fatal: [client01]: FAILED! =\> {“changed”: false, “details”: “[Errno 13] Permission denied: ‘/etc/yum.repos.d/epel.repo’”, “msg”: “Cannot open repo file /etc/yum.repos.d/epel.repo.”}

The admin user is in /etc/sudoers as being able to use sudo without entering a password. But I’m guessing you have to tell the playbook to use sudo?

What is the correct way to enter that “become-user” parameter?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 30, 2018, 6:43pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199/4 "2018-07-30T18:43:41Z")

</div>

> I think that might have fixed the immediate problem (I get the impression  
> ansible is quite picky about indentation mistakes!), but I'm getting this  
> new error:

It's actually YAML that is strict on it, and that's because the indentation have a meaning in the language.

> fatal: [client01]: FAILED! =\> {"changed": false, "details": "[Errno 13]  
> Permission denied: '/etc/yum.repos.d/epel.repo'", "msg": "Cannot open repo  
> file /etc/yum.repos.d/epel.repo."}
> 
> The admin user is in /etc/sudoers as being able to use sudo without  
> entering a password. But I'm guessing you have to tell the playbook to use  
> sudo?

Yes.

> What is the correct way to enter that "become-user" parameter?

become\_user (with an underscore) is default root so you don't need to change that.  
To enable become (become\_method default is sudo) you can add -b or --become on the command line or you can add "become: yes" (or true if you prefer) in the play like so:

- hosts: client01  
&nbsp;&nbsp;&nbsp;become: yes  
&nbsp;&nbsp;&nbsp;tasks:

---

<div class="post-metadata">

**Author:** ![Paul\_Greene](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Paul\_Greene](https://forum.ansible.com/u/Paul_Greene)\
**Post date:** [July 30, 2018, 7:23pm UTC](https://forum.ansible.com/t/cant-get-playbooks-to-work-for-creating-yum-repositories/28199/5 "2018-07-30T19:23:10Z")

</div>

Ok, thanks all. That did the trick. I also needed to add two other repos (CentOS-Base and CentOS-Updates), and once the first one was working correctly, it was easy to duplicate it for the next two.
