【发布时间】:2020-03-14 22:33:04
【问题描述】:
我想根据操作系统版本设置补丁。在 Ansible 2.8 版中提出了这个剧本。但它在调试行中给出The task includes an option with an undefined variable. 错误消息。
---
- hosts: all
gather_facts: yes
vars:
patch_name_8: 'centos8-updates'
patch_name_7: 'centos7-updates'
tasks:
- name: Set fact for CentOS 7
set_fact:
install_patch_name: "{{ patch_name_7 }}"
when: ansible_distribution_major_version == 7
- name: Set fact for CentOS 8
set_fact:
install_patch_name: "{{ patch_name_8 }}"
when: ansible_distribution_major_version == 8
- name: patch name display
debug:
msg: "install {{ install_patch_name }}"
如何根据操作系统版本设置install_patch_name变量值?
添加错误信息:
TASK [patch name display] ************************************************************************************************************
fatal: [host01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'install_patch_name' is undefined\n\nThe error appears to be in 't.yaml': line 23, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n
- name: patch name display\n ^ here\n"}
谢谢
【问题讨论】:
-
虽然这不是你问的,但你想要的不是
set_fact:install_patch_name: centos{{ ansible_distribution_major_version }}-updates吗? -
此外,拥有近 12k 的声誉,您肯定知道最好不要在不包含日志或
debug: var=ansible_distribution_major_version的输出的情况下发布这样的问题,这将使某人能够,您知道,真正帮助您跨度> -
@mdaniel,道歉不包括错误消息。现在添加它。
-
所需的信息(我在下面的答案中猜到了)将是完整的剧本结果,每个人都可以看到每个
set_fact操作实际上被跳过了。
标签: ansible