我有一本剧本
# TO CREATE USERS
- hosts: '{{host_name}}'
remote_user: ec2-user
become: yes
vars:
user_password: "{{ password }}"
user_name: "{{ username }}"
tasks:
#Adding a new user with the user module
- name: Creating user
user: name={{ user_name }} password={{ user_password|password_hash('sha512') }}
执行此操作时,我将host_name用户和密码作为额外的vars提供给
等剧本ansible-playbook xxx.yml -e "host_name=xxx username=xxx password=xxx"
我想使用vars_prompt更改此播放,以便我不必以这种方式提供此3值,我想执行此播放然后需要逐个提示主机名,用户和密码然后输入值,现在我怎么修改这个戏剧就像那样 更新我使用了来自SO的答案并进行了编辑,但仍然出现错误
# TO CREATE USERS
- hosts: localhost
gather_facts: no
remote_user: ec2-user
become: yes
vars_prompt:
- name: target_host
prompt: please enter the target host IP
private: no
- name: user_name
prompt: Enter username
private: no
- name: user_password
prompt: enter password
private: yes
encrypt: "sha512_crypt"
confirm: yes
salt_size: 7
tasks:
- add_host:
name: "{{ target_host }}"
groups: dynamically_created_hosts
- hosts: dynamically_created_hosts
tasks:
##Adding a new user
- name: Creating user
user: name={{ user_name }} password={{ user_password }}
错误
user_password is undefined