【发布时间】:2020-10-08 00:47:09
【问题描述】:
我有一个要循环的列表,问题是它给出了一个奇怪的顺序。
param.yml 文件:
my_list:
a: val1
b: val2
c: val3
d: val3
这是我的简单调试循环:
- name: debug
debug:
msg: "{{ item }}"
loop: "{{ my_list | list }}"
这里是输出:
ok: [host] => (item=a) => {
"msg": "a"
}
ok: [host] => (item=c) => {
"msg": "c"
}
ok: [host] => (item=b) => {
"msg": "b"
}
ok: [host] => (item=d) => {
"msg": "d"
}
我将 ansible 2.10 与 python 2.7.5 一起使用:
ansible --version
ansible 2.10.2
config file = /home/ansible.cfg
configured module search path = [u'/home/ansible/library']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
我切换到python3时的问题,它按预期工作:
ok: [host] => (item=a) => {
"msg": "a"
}
ok: [host] => (item=b) => {
"msg": "b"
}
ok: [host] => (item=c) => {
"msg": "c"
}
ok: [host] => (item=d) => {
"msg": "d"
}
很遗憾,我无法将环境升级到 python3,我需要列表与 param.yml 文件中的顺序相同。
谢谢!
【问题讨论】:
标签: python-2.7 ansible