# How to add hosts with yaml files?

**URL:** <https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745>\
**Category:** Get Help\
**Tags:** awx\
**Created:** [February 7, 2024, 1:57pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745 "2024-02-07T13:57:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gothsome](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gothsome](https://forum.ansible.com/u/gothsome)\
**Post date:** [February 7, 2024, 1:57pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/1 "2024-02-07T13:57:48Z")

</div>

Hello!  
I know how to add the hosts via die inventory ini and GitHub, but i have no success until now with yml/yaml. i used a simple onne from [here](https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html#passing-multiple-inventory-sources) but i get the error tha yaml file would be no yaml file:

```auto
[WARNING]: * Failed to parse /runner/project/add_nagios-ssh-rsa.yaml with yaml
plugin: We were unable to read either as JSON nor YAML, these are the errors we
got from each: JSON: Expecting value: line 1 column 1 (char 0) Syntax Error
while loading YAML. did not find expected node content The error appears to
be in '/runner/project/add_nagios-ssh-rsa.yaml': line 1, column 1, but may be
elsewhere in the file depending on the exact syntax problem. The offending
line appears to be: ... ^ here

```

The yaml:

```auto
...
  hosts:
    Nagios_3_0_6:
# ansible_ssh_common_args: "HostKeyAlgorithms=ssh-rsa"
      ansible_host: 192.168.150.20

```

Thank you for your Input again!

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [February 7, 2024, 2:09pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/2 "2024-02-07T14:09:16Z")

</div>

How about below ?

```yaml
all:
  hosts:
    Nagios_3_0_6:
# ansible_ssh_common_args: "HostKeyAlgorithms=ssh-rsa"
      ansible_host: 192.168.150.20

```

Documentation on `...` is probably an ellipsis. This causes invalid yaml errors.

---

<div class="post-metadata">

**Author:** ![kevin\_codey](https://avatars.discourse-cdn.com/v4/letter/k/e99b99/32.png) [@kevin\_codey](https://forum.ansible.com/u/kevin_codey)\
**Post date:** [February 7, 2024, 2:28pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/3 "2024-02-07T14:28:46Z")

</div>

Unless I’m mistaken, the ellipses is actually the symbol for the end of a yaml document. The interpreter will not look past that symbol.

This file shows 1 box running 3 servers and creates 3 groups against which plays can be written.

```auto
---
  all: 
    children: 
      admin_node: 
        hosts: 
          node1admin: '' 
      managed_nodes: 
        hosts: 
          node1managed1: '' 
          node1managed2: '' 
      os_servers: 
        hosts: 
          node1.aepsc.com: '' 
    hosts: 
      node1.aepsc.com: 
       operating_system: 'Linux' 
       host_name: 'node1.aepsc.com' 
      node1admin: 
       operating_system: 'Linux' 
       host_name: 'node1.aepsc.com' 
       user_comment: 'admin server' 
      node1managed1: 
       operating_system: 'Linux' 
       host_name: 'node1.aepsc.com' 
       user_comment: 'managed node 1' 
      node1managed2: 
       operating_system: 'Linux' 
       host_name: 'node1.aepsc.com' 
       user_comment: 'managed node 2'

```

---

<div class="post-metadata">

**Author:** ![gothsome](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gothsome](https://forum.ansible.com/u/gothsome)\
**Post date:** [February 8, 2024, 10:47am UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/4 "2024-02-08T10:47:24Z")

</div>

i thought i have to use a … at the beginning of every yml file.

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [February 8, 2024, 2:59pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/5 "2024-02-08T14:59:23Z")

</div>

[https://docs.ansible.com/ansible/latest/reference\_appendices/YAMLSyntax.html#yaml-basics](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html#yaml-basics)

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [February 8, 2024, 3:25pm UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/6 "2024-02-08T15:25:48Z")

</div>

Have you tried my suggestions?  
If you tried it, could you comment clearly on what the results were?  
To clarify the status of this topic.

---

<div class="post-metadata">

**Author:** ![gothsome](https://avatars.discourse-cdn.com/v4/letter/g/278dde/32.png) [@gothsome](https://forum.ansible.com/u/gothsome)\
**Post date:** [February 12, 2024, 8:27am UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/7 "2024-02-12T08:27:50Z")

</div>

Im on it today again

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 13, 2024, 8:28am UTC](https://forum.ansible.com/t/how-to-add-hosts-with-yaml-files/3745/8 "2024-03-13T08:28:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
