How to avoid repetitive entries?

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:

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.

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.

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

"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