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 }}'

只需让他们输入以空格分隔的列表,因为您已经在使用 ; 将节点名称与 IP 分开,而且它还省去了提示输入计数的麻烦,因为计数会不管列表中有多少项目

with_sequence 仅适用于任务。

所以只需在 vars_prompt 中保留一个变量 node_list 并将“,”分隔列表 ['asd;1.1.1.1','sdf;2.2.2.2'] 作为值传递。