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

标签 linux ansible centos redhat

我有一个安装了 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/

相关文章:

Python - 在给定目录中非递归地创建文件列表

centos - 使用 Ansible 检查服务是否存在

ansible - 如何使用 Ansible 在 $USER $HOME 中创建文件夹

linux - OpenEMM 未在 Tomcat 中启动

file - 文件的修改日期是否表明该文件已被lighttpd使用?

python - 将数据从 c++ 程序传递到 linux 上的 python 程序

python - 将 python IDLE 更新到 3.5

python - 我无法在 ubuntu 中创建仅设置为 python3 的虚拟环境

ansible - 如何在 ansible 1.9.4 中使用 --ask-become-pass

php - 执行命令给 top : failed tty get