I try to set up chroot for sftp users, so that they can see user/group names on ls -l
as per this article. To this end I need to get output of getent
command and place it into /chroots/{{ user.username }}/etc/passwd
file.
I try to use Ansible to replace this command getent passwd sftpuser > /chroots/sftpuser/etc/passwd
as follows:
- name: get {{ user.username }} user info
getent:
database: passwd
key: "{{ user.username }}"
- debug:
var: getent_passwd
- name: create /chroots/{{ user.username }}/etc/passwd file
lineinfile:
path: /chroots/{{ user.username }}/etc/passwd
line: "{{ getent_passwd | from_json }}"
state: present
create: yes
owner: root
group: root
mode: '0644'
The 'getent_passwd' looks as follows:
ok: [cf1] => {
"getent_passwd": {
"testuser1": [
"x",
"1001",
"1002",
"",
"/home/testuser1",
"/usr/sbin/nologin"
]
}
}
But I get this error: FAILED! => {"failed": true, "msg": "Unexpected templating type error occurred on ({{ getent_passwd | from_json }}): expected string or buffer"}
- What is the proper way to get those values supplied by
getent_passwd
into one flat string joined by ":"? - Is it safe to use genent module with
key: "root"
this way instead ofecho "root:x:0:0:not really root:::" >> /chroots/sftpuser/etc/passwd
? - one can run
getent passwd user1 user2
- is it possible to supply two keys to the ansible's getent module somehow?