问题
In short... how can I make something like this work (without vars_prompt
?!):
- name: Manual User - Input Password
delegate_to: localhost
pause:
prompt: "Enter password"
private: yes
encrypt: "sha512_crypt"
confirm: yes
salt_size: 7
register: password_manual_user
As "prompt" in pause is not the same as the prompt module, this does not work. But it shows what I would like to achieve.
More details...
I am setting up a new cloud server in an ansible playbook, this works fine.
I then want to add two users before I prevent root login. One user 'ansible' to do automated stuff and one user for logging in manually.
Before adding the 'manual user' I want to input username and password. But to be self-contained I would prefer to include the prompt in the 'users_create_sudo_user_with_password.yml' task file instead of the 'root playbook'. Besides combining the codes that belong together, I don't want to enter the usernames if the server already exists.
The relevant parts of my playbook:
---
- hosts: localhost
tasks:
- name: Create the virtual server
...
register: server
- include: task-files/users_create_ansible_user.yml
delegate_to: '{{ server.ipv4_address }}'
remote_user: root
- include: task-files/users_create_sudo_user_with_password.yml
delegate_to: '{{ server.ipv4_address }}'
remote_user: root
In an own playbook the following works:
---
- hosts: hosts2workwith
become: yes
vars_prompt:
- name: "user"
prompt: "Enter user name"
private: no
- name: "password"
prompt: "Enter password"
private: yes
encrypt: "sha512_crypt"
confirm: yes
salt_size: 7
tasks:
- name: "Create user"
user:
name: "{{ user }}"
password: "{{ password }}"
...
As vars_prompt
seems to not work in task files I need something else. For the username I can do something like:
- name: Manual User - Input Username
delegate_to: localhost
pause:
prompt: "Enter a name for the manual user:"
register: username_manual_user
But for the password?
来源:https://stackoverflow.com/questions/61864035/ansible-how-to-add-a-password-prompt-in-tasks-file