Can't get playbooks to work for creating yum repositories

1,270 views
Skip to first unread message

Paul Greene

unread,
Jul 30, 2018, 1:32:37 PM7/30/18
to Ansible Project
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

and copied this content:

- 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

Matt Martz

unread,
Jul 30, 2018, 1:34:58 PM7/30/18
to ansible...@googlegroups.com
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:


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d680fd46-d17f-438a-8112-a9ba72328039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Paul Greene

unread,
Jul 30, 2018, 2:00:15 PM7/30/18
to ansible...@googlegroups.com
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?


Kai Stian Olstad

unread,
Jul 30, 2018, 2:43:52 PM7/30/18
to ansible...@googlegroups.com
On 30.07.2018 19:59, Paul Greene wrote:
> 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
become: yes
tasks:


--
Kai Stian Olstad

Paul Greene

unread,
Jul 30, 2018, 3:23:33 PM7/30/18
to ansible...@googlegroups.com
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.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages