大网数据广告活动
服务器运维问答

Ansible 'ERROR! Missing target hosts'

· 52CE 我爱测

I'm trying to get some very basic things working with Ansible 2.1.1.0 on OS X. My targets are all Ubuntu 16.04, so the very first thing I have to do is get it to install python2.7, as without that even 'ping' won't work. I have a…

问题原文

原帖链接 · Synchro · CC BY-SA 3.0

I'm trying to get some very basic things working with Ansible 2.1.1.0 on OS X.

My targets are all Ubuntu 16.04, so the very first thing I have to do is get it to install python2.7, as without that even 'ping' won't work.

I have an inventory set up like this in servers:

[dbservers]
192.168.x.x set_hostname=db

[webservers]

[servers:children]
dbservers
webservers

And this is my play in init.yml:

---
- hosts: servers
  gather_facts: False
  become: yes
  tasks:
     - name: apt-get update
       raw: /usr/bin/apt-get update -qq
     - name: Install python 2.7
       raw: test -e /usr/bin/python || /usr/bin/apt-get install -q -y python2.7 python-simplejson

I check that it's selecting the right hosts by specifying the dbservers group, which is a subset of servers (there is only 1 anyway), which looks right to me:

# ansible dbservers -i servers --list-hosts
  hosts (1):
    192.168.x.x

The command I'm running is this:

# ansible dbservers -i servers init.yml

and that's when I get the error ERROR! Missing target hosts. I don't understand how it can have hosts and no hosts at the same time! What am I doing wrong?

已采纳解答

原帖链接 · Henrik Pingel · CC BY-SA 3.0

You are trying to run a playbook with the ansible command. The ansible command is for add-hoc commands.

Try executing your playbook with ansible-playbook command:

ansible-playbook -i servers init.yml

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。