configuration - Ansible,字段参数具有无效值

标签 configuration ansible provisioning configuration-management

<分区>

我在 playbook.yml 中添加了一个名为 common 的角色,但配置失败并显示以下消息:

TASK [common : Host is present] ************************************************
==> cd: fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'host_ip'\n\nThe error appears to have been in '/vagrant/ansible/roles/common/tasks/main.yml': line 7, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Host is present\n  ^ here\n"}

这里是roles/common/tasks/main.yml的内容,失败的特定任务

- name: Host is present
  lineinfile:
    dest: /etc/hosts
    regexp: "^{{ item.host_ip }}"
    line: "{{ item.host_ip }} {{ item.host_name }}"
  with_items: hosts
  tags: [common]

这里是roles/common/defaults/main.yml的内容

hosts: [
  { host_ip: "10.100.198.200", host_name: "cd"},
  { host_ip: "10.100.198.201", host_name: "prod"},
  { host_ip: "10.100.198.202", host_name: "logging"},
  { host_ip: "10.100.194.201", host_name: "serv-disc-01"},
  { host_ip: "10.100.194.202", host_name: "serv-disc-02"},
  { host_ip: "10.100.194.203", host_name: "serv-disc-03"},
  { host_ip: "10.100.193.200", host_name: "proxy"},
  { host_ip: "10.100.192.200", host_name: "swarm-master"},
  { host_ip: "10.100.192.201", host_name: "swarm-node-1"},
  { host_ip: "10.100.192.202", host_name: "swarm-node-2"},
]

obsolete_services:
  - puppet
  - chef-client

为什么 ansible 声称 args 是未定义的。我正在使用的示例不是我制作的,而且已经几个月了,所以我想知道,ansible 处理角色中的变量的方式是否发生了变化,因此它不起作用。

最佳答案

with_items: hosts

这是过时的语法。您不能将裸变量用于循环。

正确的语法:with_items: "{{ hosts }}"

关于configuration - Ansible,字段参数具有无效值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40381856/

相关文章:

ios - 无法在 Visual Studio 2013 for Xamarin Projects 中从 iPhone 切换到 iPhoneSimulator

java - 将基于 Spring XML 的配置转换为基于 Java 的配置

configuration - 有没有办法用配置中的属性丰富日志?

automation - 具有多个寄存器值的 Ansible 循环

Ansible 删除堆栈并提供终止保护

ios - XCode 6 和没有 XC 的 Ad-Hoc 分发 : provisioning

c# - 使用 ServerManager 在应用程序中创建应用程序

ansible - 如何在 Keycloak 中导入领域并退出

mysql - vagrant ssh 配置 - mysql 密码

iphone - Apple年度测试设备限额