How to avoid repetitive entries?

77 views
Skip to first unread message

Hilco Wijbenga

unread,
Sep 16, 2014, 1:32:47 PM9/16/14
to Ansible Project
Hi all,

I have a "user-vars.yml" file that contains a user and password. I
also want to set "sudo: True" and "remote_user: root". Right now I
repeat all that per hosts entry:

---
- hosts: all
vars:
include_vars: user-vars.yml
sudo: True
remote_user: root
roles:
- role-1
- role-2
- hosts: devbox
vars:
include_vars: user-vars.yml
sudo: True
remote_user: root
roles:
- role-3
- role-4

I tried putting the "vars", "sudo", and "remote_user" entries at a
higher level but then Ansible complains it wants a "hosts" entry. Is
there a way to avoid repeating this information?

Cheers,
Hilco

Michael DeHaan

unread,
Sep 16, 2014, 1:45:26 PM9/16/14
to ansible...@googlegroups.com
Generally I consider it an important part of play documentation though some of these defaults can be set in ansible.cfg.

You can also set variables like "ansible_ssh_user" and "ansible_sudo" (boolean) in variables.




--
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/CAE1pOi04OVom-5C6kBWDVC%2Bfq3PmSA8UT2xQMf_Wk9LxK4mKug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hilco Wijbenga

unread,
Sep 16, 2014, 1:53:17 PM9/16/14
to Ansible Project
On 16 September 2014 10:45, Michael DeHaan <mic...@ansible.com> wrote:
> Generally I consider it an important part of play documentation though some
> of these defaults can be set in ansible.cfg.

Actually, I noticed that even these repeated settings do not work. It
seems this actually needs to be done at the role level?

> You can also set variables like "ansible_ssh_user" and "ansible_sudo"
> (boolean) in variables.

Ah, yes, I had actually noticed "remote_user" but "ansible_sudo" seems
undocumented? At least Google didn't know about it.

Michael DeHaan

unread,
Sep 16, 2014, 1:59:00 PM9/16/14
to ansible...@googlegroups.com
"Actually, I noticed that even these repeated settings do not work. It
seems this actually needs to be done at the role level?"

Those settings where you have them are correct.

I'm not sure what "doesn't work" means in your case, you'll have to provide a bit more info/output there.

Yes, ansible_sudo does appear undocumented, as does the ansible_su boolean which does the same thing.

Normally something we'd refer to in the "Magic Variables" section at least.

Do you mind filing a ticket about that one?  We can add those in.

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

Hilco Wijbenga

unread,
Sep 16, 2014, 2:49:25 PM9/16/14
to Ansible Project
On 16 September 2014 10:58, Michael DeHaan <mic...@ansible.com> wrote:
> "Actually, I noticed that even these repeated settings do not work. It
> seems this actually needs to be done at the role level?"
>
> Those settings where you have them are correct.
>
> I'm not sure what "doesn't work" means in your case, you'll have to provide
> a bit more info/output there.

I use the variables in a template in a task:
roles/role-1/tasks/task-1. If I do not include the user-vars.yml file
again at the role level (mmm, or rather the task level, I guess)
Ansible complains that it does not know about those variables. Hence
my comment.

roles/role-1/tasks/task-1.yml:
- name: ...

- include_vars: user-vars.yml

- name: "task-name"
template:
src=template.j2
dest=/etc/some-file

This fails without the "include_vars" bit despite the inclusion higher up.

> Yes, ansible_sudo does appear undocumented, as does the ansible_su boolean
> which does the same thing.
>
> Normally something we'd refer to in the "Magic Variables" section at least.
>
> Do you mind filing a ticket about that one? We can add those in.

https://github.com/ansible/ansible/issues/9031
Reply all
Reply to author
Forward
0 new messages