var 提示符下的 Ansible 循环
Ansible loop on var prompt
我想在我的 bigip 上创建几个节点。为此,我想在我的 var 提示上做一个循环,并在我的变量 {{node_list}} 中注册每个值。
这是我试过的
- name: node creation
hosts: F5
gather_facts: no
connection: local
vars_prompt:
## ASK NUMBER OF NODES
- name: node_nb
prompt: "number of nodes"
private: no
## ASK THE NAME AND IP WITH FORMAT NAME;IP
- name: node_list
prompt: "name and Ip of the node like that toto;1.1.1.1"
private: no
with_sequence: count={{ node_nb | int }}
- name: Create node
bigip_node:
user: '{{ ansible_user }}'
password: '{{ ansible_password }}'
server: 'xxxxx'
host: '{{ (item).split(";")[1] }}'
name: '{{ (item).split(";")[0] }}'
partition: 'Common'
state: present
validate_certs: false
with_items: '{{ node_list }}'
首先:
例如,如果我在 {{ node_nb }} 中指定“4”,我的 var 提示不会循环。问题提示1次,我要4次
第二:
我每次都会在列表中注册输入值的所有信息。如果我想要 4 个节点,我的列表中需要有 4 个项目
只需让他们输入以空格分隔的列表,因为您已经在使用 ;
将节点名称与 IP 分开,而且它还省去了提示输入计数的麻烦,因为计数会不管列表中有多少项目
with_sequence
仅适用于任务。
所以只需在 vars_prompt 中保留一个变量 node_list
并将“,”分隔列表 ['asd;1.1.1.1','sdf;2.2.2.2']
作为值传递。
我想在我的 bigip 上创建几个节点。为此,我想在我的 var 提示上做一个循环,并在我的变量 {{node_list}} 中注册每个值。
这是我试过的
- name: node creation
hosts: F5
gather_facts: no
connection: local
vars_prompt:
## ASK NUMBER OF NODES
- name: node_nb
prompt: "number of nodes"
private: no
## ASK THE NAME AND IP WITH FORMAT NAME;IP
- name: node_list
prompt: "name and Ip of the node like that toto;1.1.1.1"
private: no
with_sequence: count={{ node_nb | int }}
- name: Create node
bigip_node:
user: '{{ ansible_user }}'
password: '{{ ansible_password }}'
server: 'xxxxx'
host: '{{ (item).split(";")[1] }}'
name: '{{ (item).split(";")[0] }}'
partition: 'Common'
state: present
validate_certs: false
with_items: '{{ node_list }}'
首先: 例如,如果我在 {{ node_nb }} 中指定“4”,我的 var 提示不会循环。问题提示1次,我要4次
第二: 我每次都会在列表中注册输入值的所有信息。如果我想要 4 个节点,我的列表中需要有 4 个项目
只需让他们输入以空格分隔的列表,因为您已经在使用 ;
将节点名称与 IP 分开,而且它还省去了提示输入计数的麻烦,因为计数会不管列表中有多少项目
with_sequence
仅适用于任务。
所以只需在 vars_prompt 中保留一个变量 node_list
并将“,”分隔列表 ['asd;1.1.1.1','sdf;2.2.2.2']
作为值传递。