我正在尝试开发一个可以让root用户随时通过运行playbook轻松重置密码的剧本。但是它可以跳过进行验证的预处理。
---
- hosts: localhost
remote_user: root
become: yes
become_method: sudo
vars_prompt:
- name: "root_password"
prompt: "Enter your new root password"
private: no
when: root_password is not defined
pre_tasks:
- name: fail the play if the user missed out root_password
fail: msg="root password should not be empty"
when: root_password is not defined
tasks:
- name: Change root password
user: name=root update_password=always password={{ root_password }}
答案 0 :(得分:1)
任务设置为在未定义root_password
且您输入的任何值时运行,您可以在vars_prompt
部分中定义它。因此,该任务被跳过。
根据你想要在它空的时候失败的消息来判断,所以条件应该是:
when: root_password == ""