我在Ansible中具有以下要求。它会提示以下菜单并选择一个选项。
从下面的菜单中选择您的要求
对于选项1,需要再次询问;
对于选项2,需要再次询问;
提示以下菜单;
我已经尝试使用vars_prompt,因为我是新手,因此只能使用条件变量和vars_prompt。
---
- name: Inventory automation for SMGT clients
hosts: localhost
vars_prompt:
- name: "options"
prompt: "\nChoose your requirement from the below menu:\n\n1. Add new name.\n2. Modify an existing name\n\n"
private: no
- name: "client"
prompt: "\nName "
private: no
when: (options == "1")
- name: "client_id"
prompt: "\nEnter the ID "
private: no
when: options == "1"
- name: "modify"
prompt: "\nEdit name "
private: no
when: (options == "2")
- name: "new_name"
prompt: "\nNew name "
private: no
when: options == "2"
...
有人可以引导我吗?我已经在网上搜索过,但是没有找到教程。
答案 0 :(得分:1)
怎么样?
---
- hosts: localhost
connection: local
gather_facts: false
tasks:
- pause:
prompt: "Main menu: enter 1 or 2"
register: main_input
- set_fact:
main_var: "{{ main_input.user_input }}"
- pause:
prompt: "Submenu A"
register: submenu_a_input
when: main_var == "1"
- pause:
prompt: "Submenu B"
register: submenu_b_input
when: main_var != "1"