Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash Ansible多变量包含多个值_Bash_Variables_Ansible - Fatal编程技术网

Bash Ansible多变量包含多个值

Bash Ansible多变量包含多个值,bash,variables,ansible,Bash,Variables,Ansible,以下是我的一些任务: - name: counting object from json shell: > jq '.results[].stdout_lines | length' backup/{{ inventory_hostname }}_rsl.json | wc -l register: jsondata - name: counting object converting shell: > seq 0

以下是我的一些任务:

    - name: counting object from json
     shell: >
      jq '.results[].stdout_lines | length' backup/{{ inventory_hostname }}_rsl.json | wc -l
     register: jsondata
   - name: counting object converting
     shell: >
      seq 0 {{ jsondata.stdout|int - 1 }} | tr '\n' ' ' | xargs | sed 's/[[:space:]]/,/g'
     register: seq
   - name: get interface
     shell: >
      cat backup/{{ inventory_hostname }}_{{ item }}_rsl_result_nows.json | cut -d, -f1
     register: interface
     with_items:
      - "{{ seq.stdout.split(',') | list }}"
   - name: get rsl value
     shell: >
      cat backup/{{ inventory_hostname }}_{{ item }}_rsl_result_nows.json | cut -d, -f2-
     register: rslvalue
     with_items:
      - "{{ seq.stdout.split(',') | list }}"
   - name: post to DB via curl
     shell: >
      curl -d "ip_address={{ inventory_hostname }}&hostname={{ varhostname.stdout }}&interface={{ interface }}&rslvalue={{ rslvalue }}" -X POST http://dev.trm.net:8088/ip_planning/rsl/postrsl -v
我想发布具有相同主机名但不同接口和一些其他属性的数据

这是我想要的curl命令:

curl -d "ip_address=IP_A&hostname=HOST_A&interface=IFACE_1&rslvalue=1,2,3,4,5" -X POST http://dev.trm.net:8088/ip_planning/rsl/postrsl -v

curl -d "ip_address=IP_A&hostname=HOST_A&interface=IFACE_2&rslvalue=5,4,3,2,1" -X POST http://dev.trm.net:8088/ip_planning/rsl/postrsl -v

curl -d "ip_address=IP_B&hostname=HOST_B&interface=IFACE_1&rslvalue=11,21,31,41,51" -X POST http://dev.trm.net:8088/ip_planning/rsl/postrsl -v
我累了一整天,请帮帮我。我已经尝试了上面的ansible脚本,但出现了错误

“msg”:“该任务包含一个带有未定义变量的选项。错误为:'item'未定义。”


在上一个任务中有
{{item.interface.stdout}
,但with\u项不存在。
另外,当您在shell命令中使用item时,请使用as
“{{item}”

一点改进让我觉得很有趣

   - name: post to DB via curl
     shell: >
      curl -d "ip_address={{ inventory_hostname }}&hostname={{ varhostname.stdout }}&interface={{ item }}&rslvalue={{ item }}" -X POST http://dev.tr$
     with_items:
      - "{{ rslvalue.results | map(attribute='stdout') | list }}"
      - "{{ interface.results | map(attribute='stdout') | list }}"

但是“item”变量总是打印“rslvalue”结果。如何声明“item”具有多个with\u项???

对于哪个任务,您会得到此错误上一个任务“post to DB via curl”您在任务中有{item.interface.stdout},但with\u项不存在如何使用多个with\u项?我想在中使用具有不同值的“item”变量interface={item}}和“rslvalue={{{item}}”curl命令如何使用多个with_items?我想在“interface={{item}}”和“rslvalue={{item}”curl命令中使用具有不同值的“item”变量,并使用_嵌套签出