我在RHEL 7主机上使用ansible 2.0.1。以某种方式跟随角色,当通过游戏手册调用时,跳过Get的黄色主版本。在下面附加输出。好像是什么时候的状况出了问题。
- set_fact: is_yos="true"
- name: Fetch yellow version
shell: /bin/gawk '{ for(col = 1; col <= NF; col++) if ($col ~ /[0-9.]+/) { print $col; } }' /etc/yellow-release
register: yel_ver_str
failed_when: false
changed_when: false
- set_fact:
is_yos: "false"
when: yel_ver_str.rc != 0
- debug: var=yel_ver_str
- debug: var=is_yos
- name: Get yellow major version.
shell: echo {{ yel_ver_str.stdout }} | awk -F. '{print $1}'
register: yel_major_ver
when: is_yos == "true"
delegate_to: localhost
changed_when: false输出
ansible-playbook -i hosts test.yml -c local
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [172.31.83.23]
TASK [test : set_fact] *********************************************************
ok: [172.31.83.23]
TASK [test : Fetch yellow version] *********************************************
ok: [172.31.83.23]
TASK [test : set_fact] *********************************************************
skipping: [172.31.83.23]
TASK [test : debug] ************************************************************
ok: [172.31.83.23] => {
"yel_ver_str": {
"changed": false,
"cmd": "/bin/gawk '{ for(col = 1; col <= NF; col++) if ($col ~ /[0-9.]+/) { print $col; } }' /etc/yellow-release",
"delta": "0:00:00.004225",
"end": "2016-04-22 13:37:29.517570",
"failed": false,
"failed_when_result": false,
"rc": 0,
"start": "2016-04-22 13:37:29.513345",
"stderr": "",
"stdout": "7.2.0",
"stdout_lines": [
"7.2.0"
],
"warnings": []
}
}
TASK [test : debug] ************************************************************
ok: [172.31.83.23] => {
"is_yos": true
}
TASK [test : Get yellow major version.] ****************************************
skipping: [172.31.83.23]
PLAY RECAP *********************************************************************
172.31.83.23 : ok=5 changed=0 unreachable=0 failed=0发布于 2016-04-22 15:29:53
查看您的debug任务的输出:
TASK [test : debug] ************************************************************
ok: [172.31.83.23] => {
"is_yos": true
}is_yos事实是一个布尔变量(true是一个布尔值,而"true"是一个字符串值)。所以当你测试:
when: is_yos == "true"检查是假的,因为您正在将布尔值与字符串进行比较。相反,请使用:
when: is_yoshttps://stackoverflow.com/questions/36795760
复制相似问题