Optional non-empty passwords for the container user.

This commit is contained in:
Andreas B. Mundt 2021-11-12 15:29:39 +01:00 committed by Andreas B. Mundt
parent 1b5f7ea0b5
commit baba55e05a
2 changed files with 12 additions and 2 deletions

View file

@ -7,6 +7,9 @@
become: yes
vars:
contname: cont
## Password for the user 'ansible' in the container,
## leave empty to log in without password:
contpwd: ""
containers: "{{ range(0, 9 + 1) | list }}"
extra_pkgs: [apt-cacher-ng]

View file

@ -103,14 +103,21 @@
cmd: chroot . sh -c "passwd -d ansible"
args:
chdir: /var/lib/machines/{{ contname }}00
when: user_account.changed | default(false)
when: user_account.changed | default(false) and contpwd | length == 0
- name: provide password for container ansible user
command:
cmd: chroot . sh -c "echo ansible:{{ contpwd }} | chpasswd"
args:
chdir: /var/lib/machines/{{ contname }}00
when: user_account.changed | default(true) and contpwd | length > 0
- name: allow empty passwords in ssh
lineinfile:
path: /var/lib/machines/{{ contname }}00/etc/ssh/sshd_config
insertafter: '#PermitEmptyPasswords no'
line: 'PermitEmptyPasswords yes'
when: user_account.changed | default(false)
when: user_account.changed | default(false) and contpwd | length == 0
- name: prepare directories
file: