Answers: <p>Just add <code>hosts</code> before every block of hosts.
  I.e., under the group level, you should have <code>hosts</code> directive</p>
  
  <p>See <a href="https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml#L8" rel="nofollow noreferrer">ansible source code example</a>:</p>
  
  <blockquote>
    <p><code>- Hosts must be specified in a group's hosts:</code></p>
  </blockquote>
  
  <p>Working inventory.yml:</p>
  
  <pre><code>all:
    children:
      control:
        hosts:
          localhost
          127.0.0.1
      managed:
        hosts:
         localhost
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-07T14:31:35.033Z
Answers: 2020-03-07T14:31:35.033Z
Answers: Yasen
Answers: <p>The keyword <code>hosts</code> is missing. Also colons <code>:</code> are needed after the hostnames. Fix the syntax, for example</p>
  <pre class="lang-yaml prettyprint-override"><code>all:
    children:
      control:
        hosts:
          moriarty.server.com:
          toby.server.com:
      managed:
        hosts:
          sherlock.server.com:
  </code></pre>
  <p>See <a href="https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#how-to-build-your-inventory" rel="nofollow noreferrer">How to build your inventory</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-03-07T23:38:48.310Z
Answers: Perfect, thanks!
Answers: Lucky The Rabbit
Answers: CC BY-SA 4.0
Answers: 2020-03-07T14:35:44.367Z
Answers: 2021-01-14T10:53:40.167Z
Answers: 2021-01-14T10:53:40.167Z
Answers: Vladimir Botka
Body: <p>I've got the following production inventory file (<code>playbooks/production.yaml</code>) for Ansible:</p>
  
  <pre class="lang-yaml prettyprint-override"><code>all:
    children:
      control:
        moriarty.server.com
        toby.server.com
      managed:
        sherlock.server.com
  </code></pre>
  
  <p>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 <code>ansible-playbook</code> on my local machine, I get the following error:</p>
  
  <pre><code>$ 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 **************************************************************************************************************************************************************************
  </code></pre>
  
  <p>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?</p>
  
Tags: <ansible><yaml><ansible-inventory>
Title: Custom inventory file failing to parse properly
UserDisplayName: Lucky The Rabbit
ThreadText: # Custom inventory file failing to parse properly
  
  (Asked by: username_0 on 2020-03-07)
  
  I've got the following production inventory file (`playbooks/production.yaml`) for Ansible:
  
  ```yaml
  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?
  
  **Tags:** ansible, yaml, ansible-inventory
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-03-07. Score: 5 | Accepted answer
  
  The keyword `hosts` is missing. Also colons `:` are needed after the hostnames. Fix the syntax, for example
  
  ```yaml
  all:
    children:
      control:
        hosts:
          moriarty.server.com:
          toby.server.com:
      managed:
        hosts:
          sherlock.server.com:
  
  ```
  
  See [How to build your inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#how-to-build-your-inventory).
  
  > **Comments:**
  > **username_0**: Perfect, thanks!  
  
  ---
  
  ### Answer by username_1 on 2020-03-07. Score: 1
  
  Just add `hosts` before every block of hosts.
  I.e., under the group level, you should have `hosts` directive
  
  See [ansible source code example](https://github.com/ansible/ansible/blob/devel/examples/hosts.yaml#L8):
  
  > `- Hosts must be specified in a group's hosts:`
  
  Working inventory.yml:
  
  ```
  all:
    children:
      control:
        hosts:
          localhost
          127.0.0.1
      managed:
        hosts:
         localhost
  
  ```
  
  
  ---
  
  