1

I've got the following production inventory file (playbooks/production.yaml) for Ansible:

all:
  children:
    control:
      moriarty.server.com
      toby.server.com
    managed:
      sherlock.server.com

Based on what I'm reading online, it looks like it should be correct, and I can't find any syntax errors in the file using a YAML linter. However, when I run ansible-playbook on my local machine, I get the following error:

$ ansible-playbook -i playbooks/production.yaml --extra-vars target=moriarty.server.com playbooks/create-server.yaml
[WARNING]: log file at /var/log/ansible.log is not writeable and we cannot create it, aborting

[WARNING]: Skipping 'control' as this is not a valid group definition

[WARNING]:  * Failed to parse /Users/username/infra/playbooks/production.yaml with auto plugin: no root 'plugin' key found,
'/Users/username/infra/playbooks/production.yaml' is not a valid YAML inventory plugin config file

[WARNING]:  * Failed to parse /Users/username/infra/playbooks/production.yaml with yaml plugin: control is not a known host nor group

[WARNING]:  * Failed to parse /Users/username/infra/playbooks/production.yaml with ini plugin: Invalid host pattern 'all:' supplied, ending in ':' is not allowed, this
character is reserved to provide a port.

[WARNING]: Unable to parse /Users/username/infra/playbooks/production.yaml as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: moriarty.server.com


PLAY [moriarty.server.com] ************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP **************************************************************************************************************************************************************************

I'm at a loss, since it looks to be valid YAML. Do I need to format it some other way when I have groups in this manner?

1

The keyword hosts is missing. Also colons : are needed after the hostnames. Fix the syntax, for example

all:
  children:
    control:
      hosts:
        moriarty.server.com:
        toby.server.com:
    managed:
      hosts:
        sherlock.server.com:

See How to build your inventory.

| improve this answer | |
0

Just add hosts before every block of hosts. I.e., under the group level, you should have hosts directive

See ansible source code example:

- Hosts must be specified in a group's hosts:

Working inventory.yml:

all:
  children:
    control:
      hosts:
        localhost
        127.0.0.1
    managed:
      hosts:
       localhost
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.