Username variable.

This commit is contained in:
Andreas B. Mundt 2021-11-18 20:22:00 +01:00 committed by Andreas B. Mundt
parent 0c48d933e7
commit 327f2eefac
2 changed files with 10 additions and 8 deletions

View file

@ -24,6 +24,8 @@
become: yes become: yes
vars: vars:
contname: cont contname: cont
## User name for the user in the container:
contuser: ansi
## Password for the user 'ansible' in the container, ## Password for the user 'ansible' in the container,
## leave empty to log in without password: ## leave empty to log in without password:
contpwd: "" contpwd: ""

View file

@ -6,7 +6,7 @@
## container 1: ssh → host port 10001, HTTP → 10101 ## container 1: ssh → host port 10001, HTTP → 10101
## ... ... ... ## ... ... ...
## ##
## User 'ansible' in the sudo group. Password is {{ contpwd }}. ## User '{{ contuser }}' in the sudo group. Password is '{{ contpwd }}'.
## ##
- name: stop all containers - name: stop all containers
@ -91,26 +91,26 @@
args: args:
chdir: /var/lib/machines/{{ contname }}00 chdir: /var/lib/machines/{{ contname }}00
- name: provide ansible user account - name: provide {{ contuser }} user account
command: command:
cmd: > cmd: >
chroot . sh -c '/usr/sbin/useradd -m -s /bin/bash chroot . sh -c '/usr/sbin/useradd -m -s /bin/bash
-c "Ansible User,,," -G sudo ansible' -c "User {{ contuser }},,," -G sudo {{ contuser }}'
args: args:
chdir: /var/lib/machines/{{ contname }}00 chdir: /var/lib/machines/{{ contname }}00
creates: /var/lib/machines/{{ contname }}00/home/ansible creates: /var/lib/machines/{{ contname }}00/home/{{ contuser }}
register: user_account register: user_account
- name: provide empty password for ansible user - name: provide empty password for {{ contuser }} user
command: command:
cmd: chroot . sh -c "passwd -d ansible" cmd: chroot . sh -c "passwd -d {{ contuser }}"
args: args:
chdir: /var/lib/machines/{{ contname }}00 chdir: /var/lib/machines/{{ contname }}00
when: user_account.changed | default(false) and contpwd | length == 0 when: user_account.changed | default(false) and contpwd | length == 0
- name: provide password for container ansible user - name: provide password for container {{ contuser }} user
command: command:
cmd: chroot . sh -c "echo ansible:{{ contpwd }} | chpasswd" cmd: chroot . sh -c "echo {{ contuser }}:{{ contpwd }} | chpasswd"
args: args:
chdir: /var/lib/machines/{{ contname }}00 chdir: /var/lib/machines/{{ contname }}00
when: user_account.changed | default(true) and contpwd | length > 0 when: user_account.changed | default(true) and contpwd | length > 0