如何让Ansible pause模块任务状态换行并隐藏任务名称
问题解决:Ansible pause模块换行与任务名称隐藏
解决方法
1. 实现用户输入与任务状态换行显示
在pause模块的prompt内容末尾添加一个空行,用户输入完成后,Ansible会自动将任务状态输出到下一行。
2. 隐藏pause模块的任务名称
给pause任务添加quiet: true参数(需Ansible 2.11及以上版本),该参数会屏蔽任务名称及相关前置提示;同时将任务的name设为空字符串,彻底避免名称显示。
修改后的Playbook
- name: Initial Setup with Validation Prompt hosts: all gather_facts: false pre_tasks: - name: Run validation script command: python3 /tmp/validation_interface.py register: validation_result failed_when: false tags: skip_validation - name: Print validation script stdout debug: var: validation_result.stdout when: validation_result.rc != 0 tags: skip_validation - name: "" pause: quiet: true prompt: | Validation script failed Do you still want to continue with the setup? (yes/no): register: user_input when: validation_result.rc != 0 tags: skip_validation - name: Fail if user chooses not to continue fail: msg: "User aborted due to failed validation." when: - validation_result.rc != 0 - user_input.user_input != "yes" tags: skip_validation
修改后效果
执行后的输出会变成:
Executing Playbook: initial_setup.yml ---------------------------------------------------------------------------------------------- PLAY 1/1 | Initial Setup with Validation Prompt Hosts: - all 09:14:22 | Run validation script ✓ localhost CHANGED 09:14:23 | Print validation script stdout ✓ localhost OK Validation script failed Do you still want to continue with the setup? (yes/no): yes ✓ localhost OK 09:14:25 | Fail if user chooses not to continue
内容的提问来源于stack exchange,提问作者A.C
相关产品推荐
相关产品推荐

