gpt4 book ai didi

linux - ANSIBLE “ERROR! the field ' 主机是必需的,但未设置”

转载 作者:行者123 更新时间:2023-12-04 19:30:17 27 4
gpt4 key购买 nike

我有一个安装了 ansible 的 CENTOS 7 虚拟机,我正在尝试在 RED HAT 8 上安装带有 ansible 的 HTTPD 服务。

文件内容:

“主机”

[ubuntuserver]
192.168.1.51
[redhat]
192.168.56.102

“playbook.yaml”

[root @ centos7 ansible] # cat playbook.yaml
---
- hosts: redhat
- remote_user: root
tasks:
- name: install apache
yum: name = httpd
[root @ centos7 ansible] #

我得到的错误:

error

最佳答案

首先,将所有内容缩进同一级别:

- hosts: redhat
remote_user: root
tasks:
- name: install apache
yum: name = httpd

请注意,仅使用了一个 -

其次,您创建的 hosts 文件称为 inventory 。通过执行 ansible-playbook playbook.yaml ,它将使用位于 /etc/ansible/hosts 的默认 list 文件,该文件甚至可能不存在于您的计算机上。

因此,您所要做的就是告诉 ansible 使用 -i option 加载您的 list 文件。 :

ansible-playbook -i hosts plabook.yaml

关于linux - ANSIBLE “ERROR! the field ' 主机是必需的,但未设置”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67684949/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com