Actually just solved the problem myself. It seem the issue lied within the
line of my playbook:
prompt: "Enter password for new user account {{ user_name }}"
My thought is that the {{ user_name }} variable cannot be referenced since
the vars_prompt method has not finalized yet. Removing the reference of the
user_name variable solved the issue for me.
Now my code looks as so, running as wished:
---
- hosts: localhost
vars_prompt:
- name: "user_name"
prompt: "Enter username to be added to systems"
private: no
- name: "password"
prompt: "Enter password for new user account"
private: yes
encrypt: "sha256_crypt"
confirm: yes
tasks:
- name: Create new user on localhost
become: true
user:
name: "{{ user_name }}"
group: ansible
shell: /bin/bash
password: "{{ password }}"
On Friday, February 22, 2019 at 9:21:27 AM UTC-5, Kendon Emmons wrote:
>
> I am trying to get two variables in my vars_prompt, for username and
> password.
>
> My playbook currently looks like this:
>
> ---
> - hosts: localhost
> vars_prompt:
> - name: "user_name"
> prompt: "Enter username to be added to systems"
> private: no
>
> - name: "password"
> prompt: "Enter password for new user account {{ user_name }}"
> private: yes
> encrypt: "sha256_crypt"
> confirm: yes
>
>
>
>
> tasks:
> - name: Create new user on localhost
> become: true
> user:
> name: "{{ user_name }}"
> group: ansible
> shell: /bin/bash
> password: "{{ password }}"
>
>
>
> When I run the playbook from my system, I receive the following error:
>
> ERROR! 'user_name' is undefined
>
>
> I do not receive an error when I signify extra variable from the command
> line as so:
>
> ansible-playbook ./testing/encrypted_passwords.yml -e "user_name=test2"
>
> I see in the Ansible documentation that you are able to do two variables
> within the vars_prompt,
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html
>
> Any help would be appreciated, thank you!
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.