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.
- 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
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:
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.
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:
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.