1

我正在尝试运行剧本

ansible-playbook \
  -i inventory/preprod/inventory.ini \
  --private-key ~/.ssh/id_rsa_stagging \
  -u cloud-user \
  --become \
  --become-user=root \
  cluster.yml \
  --tags resolvconf

它返回此错误:

fatal: [tivit-aiops-k8s-preprd-app-1]: FAILED! => {
  "msg": "The field 'environment' has an invalid 
  value, which includes an undefined variable. The error 
  was: 'ansible.vars.hostvars.HostVarsVars object' has 
  no attribute 'ansible_hostname'"
}

我不明白我做错了什么......

4

2 回答 2

2

查看Kubespray 提供的示例清单:

# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
# node1 ansible_host=95.54.0.12  # ip=10.3.0.1 etcd_member_name=etcd1
# node2 ansible_host=95.54.0.13  # ip=10.3.0.2 etcd_member_name=etcd2
# node3 ansible_host=95.54.0.14  # ip=10.3.0.3 etcd_member_name=etcd3
# node4 ansible_host=95.54.0.15  # ip=10.3.0.4 etcd_member_name=etcd4
# node5 ansible_host=95.54.0.16  # ip=10.3.0.5 etcd_member_name=etcd5
# node6 ansible_host=95.54.0.17  # ip=10.3.0.6 etcd_member_name=etcd6

有一个名称可用于通过清单文件引用此主机(用于将组分配给主机),还有一个ansible_host值指定 Ansible 将连接到的 IP(与名称分开)。

于 2019-11-25T16:59:21.917 回答
1

这是库存文件的具体示例。请注意,ansible_host设置为服务器的 IP 地址。每台服务器都需要一条线路。

[all]
ip-10-250-195-106.ec2.internal ansible_host=10.250.195.106
于 2020-07-12T02:42:29.837 回答