- name: Gather sudo users
shell: "/bin/cat /etc/{{item}} | grep -ve ^$ -e ^# -e ^Defaults"
register: sudoers
with_items:
- sudoers
- sudoers.d/*
- name: Write sudo users
lineinfile:
dest: "/tmp/{{ansible_nodename}}.sudoers"
line: "{{sudoers.stdout_lines}}"
insertafter: EOF
create: yes
state: present
delegate_to: localhost
Interesting.....
debug shows that the variable is being appended to. I can't seem to
reference anything under the var (sudoers.stdout_lines for instance).
Is it possible to grab all instances of stdout_lines with this var's
output? I've been trying without luck . . .
ok: [ansibletest-oel6] => {
"sudoers": {
"changed": true,
"msg": "All items completed",
"results": [
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/cat /etc/sudoers | grep -ve ^$ -e ^# -e ^Defaults",
"delta": "0:00:00.004715",
"end": "2017-09-29 16:08:26.616661",
"invocation": {
"module_args": {
"_raw_params": "/bin/cat /etc/sudoers | grep -ve ^$ -e ^# -e ^Defaults",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"item": "sudoers",
"rc": 0,
"start": "2017-09-29 16:08:26.611946",
"stderr": "",
"stderr_lines": [],
"stdout": "root\tALL=(ALL) \tALL",
"stdout_lines": [
"root\tALL=(ALL) \tALL"
]
},
{
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": true,
"cmd": "/bin/cat /etc/sudoers.d/* | grep -ve ^$ -e ^# -e ^Defaults",
"delta": "0:00:00.005332",
"end": "2017-09-29 16:08:26.782472",
"invocation": {
"module_args": {
"_raw_params": "/bin/cat /etc/sudoers.d/* | grep -ve ^$ -e ^# -e ^Defaults",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
}
},
"item": "sudoers.d/*",
"rc": 0,
"start": "2017-09-29 16:08:26.777140",
"stderr": "",
"stderr_lines": [],
"stdout": "gomer ALL=(ALL) NOPASSWD: ALL\npyle ALL=(ALL) NOPASSWD: ALL",
"stdout_lines": [
"gomer ALL=(ALL) NOPASSWD: ALL",
"pyle ALL=(ALL) NOPASSWD: ALL"
]
}
]
}
}
line: "{{sudoers.results|map(attribute='stdout_lines')|list}}"
[['root\tALL=(ALL) \tALL'], ['gomer ALL=(ALL) NOPASSWD: ALL', 'pyle ALL=(ALL) NOPASSWD: ALL']]
root ALL=(ALL) ALL
gomer ALL=(ALL) NOPASSWD: ALL
pyle ALL=(ALL) NOPASSWD: ALL