问题描述
我正在尝试使用循环访问变量,但它对我不起作用。
剧本
---
- name: test looping
hosts: localhost
gather_facts: False
vars:
repos:
- name: repo1
os_list:
- centos
- rhel
major_distribution_list:
- 6
- 7
- 8
archs:
- noarch
- x86_64
tasks:
- include_tasks: repo-paths.yml
with_items: "{{ repos }}"
loop_control:
loop_var: repo
- debug: msg="./{{ item.0 }}/{{ item.1 }}/{{ item.2 }}/{{ item.3 }}"
with_nested:
- "{{ repo.os_list }}"
- "{{ repo.major_distribution_list }}"
- "{{ repo.name }}"
- "{{ repo.archs }}"
但我收到错误 repo 变量未定义。 原始输出:-
PLAY [test looping] ***********************************************************************************************************************************************************
TASK [include_tasks] **********************************************************************************************************************************************************
TASK [debug] ******************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "'repo' is undefined"}
PLAY RECAP ********************************************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
预期输出:-
"msg": "./centos/6/repo1/noarch"
"msg": "./centos/6/repo1/x86_64"
"msg": "./centos/7/repo1/noarch"
"msg": "./centos/7/repo1/x86_64"
"msg": "./centos/8/repo1/noarch"
"msg": "./centos/8/repo1/x86_64"
"msg": "./rhel/6/repo1/noarch"
"msg": "./rhel/6/repo1/x86_64"
"msg": "./rhel/7/repo1/noarch"
"msg": "./rhel/7/repo1/x86_64"
"msg": "./rhel/8/repo1/noarch"
"msg": "./rhel/8/repo1/x86_64"
请帮助我,也请告诉我是否有其他方法可以做同样的事情。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)