如果我的问题有点基础的话,我对ansible很新.
场景:
我有一些远程主机组,如[EPCs] [客户端]和[测试人员]我能够按照我希望的方式配置它们.
问题:
我需要编写一个剧本,在运行时,会在运行时向用户询问库存.作为运行剧本的示例,应按以下方式提示用户:"输入要配置的EPC数量""输入要配置的客户端数量""输入要配置的测试人员数量"
会发生什么:
例如,用户分别输入2,5和8.现在,剧本应仅解决组[EPC]中的前2个节点,组[客户端]中的前5个节点以及组[测试人员]中的前7个节点.我不想创建大量的子组,例如,如果我有20个EPC,那么我不想为我的EPC定义20个组,我想要一些动态库存,它应该自动配置根据用户在运行时输入的机器使用vars_prompt选项或类似的东西
让我发布我的剧本的部分内容,以便更好地了解将要发生的事情:
---
- hosts: epcs # Now this is the part where I need a lot of flexibility
vars_prompt:
name: "what is your name?"
quest: "what is your quest?"
gather_facts: no
tasks:
- name: Check if path exists
stat: path=/home/khan/Desktop/tobefetched/file1.txt
register: st
- name: It exists
debug: msg='Path existence verified!'
when: st.stat.exists
- name: It doesn't exist
debug: msg="Path does not exist"
when: st.stat.exists == false
- name: Copy file2 …Run Code Online (Sandbox Code Playgroud) 我有3个变量名为IPOctet,ServerIPRange和epcrange.如果我在终端中执行以下操作,它可以完美地工作
IPOctet=$(echo "$ServerIPRange/$epcrange+$IPOctet" | bc)
Run Code Online (Sandbox Code Playgroud)
如何在任务中的ansible中执行类似的操作,例如
---
- hosts: localhost
gather_facts: False
vars_prompt:
- name: epcrange
prompt: Enter the number of EPCs that you want to configure
private: False
default: "1"
- name: serverrange
prompt: Enter the number of Clients that you want to configure
private: False
default: "1"
- name: ServerIPRange
prompt: Enter the ServerIP range
private: False
default: '128'
- name: LastIPOctet
prompt: Enter The last Octet of the IP you just entered
private: False
default: '10'
pre_tasks: …Run Code Online (Sandbox Code Playgroud)