ansible - 变量已定义但仍出现未定义错误
问题描述
我正在尝试编写一个在运行该剧本的机器上完成其一些任务的剧本。我知道我可以为此使用 local_action ,但我只是在测试剧本现在是否有效。最终我需要使用delegate_to。我已经定义了变量并且我正在使用 delegate_to: 'variable name' 但我收到了这个错误。: " fatal [target node]: FAILED! => { msg": "'variablename' 未定义。下面是我的剧本:
name: Create certs
gather_facts: true
vars:
master: "{{ nameofhost }}"
tasks:
- name: Run command
shell: Command to run
delegate_to: "{{ master }}"
解决方案
您需要将您的游戏定位到库存的目标主机
name: Create certs
gather_facts: true
hosts: target_hosts
vars:
master: "{{ nameofhost }}"
tasks:
- name: Run command
shell: Command to run
delegate_to: "{{ master }}"
```
Your inventory files may look like that:
[target_hosts]
master ansible_host=your_master_dns_or_ip
And then ansible can target that inventory group and then reduce the task scope to master host. Or you can just use the localhost as target.
推荐阅读
- forms - 如何在需要 POST 时防御性地拒绝 HTTP“GET”?
- java - 关于片段生命周期
- kibana - 如何将背景颜色应用于同一仪表板中的 Kibana 表(或不)
- python - 通过固定唯一的对角线值来归一化对称矩阵
- odoo-13 - Odoo 13 CRM Kanban 将列隐藏到特定组
- google-cloud-functions - Google actions webhook 部署云功能失败
- google-cloud-platform - 无法连接谷歌云外部静态ip
- operating-system - 上下文切换是影响进程同步中有限等待的唯一因素吗?
- c++ - 为什么我的合并排序程序出现分段错误错误
- visual-studio-code - 通过 VSCode-Remote-SSH 终端访问时,远程机器不要求提供私人仓库的 git 用户/密码