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?
You are trying to run a
playbook
with theansible
command. Theansible
command is foradd-hoc
commands.Try executing your playbook with
ansible-playbook
command:You have a
[servers:children]
section, but no[servers]
section in your hosts file. So when you sethosts: servers
there is no matching group.