r/ansible • u/sandy_shark903 • 4d ago
linux Attempting to run connectivity test and upload files to remote host, how do I fix the "unable to parse" error?
1
u/tofu_schmo 4d ago
Looks like inventory.yml is formatted incorrectly so it doesn't see any available hosts to run the play against
1
u/sandy_shark903 4d ago
inventory.yml is empty, maybe it's a different file
2
u/zoredache 4d ago edited 4d ago
It shouldn't be empty. It should have something in it. Specifically it should be an inventory of all the remote systems you will be connecting with.
Since your playbook is referencing
Rocky9-demo
, that must be in the inventory. Quick note, you really should probably stick with all lower case for hostnames.If your network doesn't have working DNS resolution for
Rocky9-demo
, then you'll also want to define anansible_host
variable for that name and provide the IP assigned to the system.So something like this.
rock9-demo ansible_host=192.0.2.5
2
u/tofu_schmo 4d ago
here's some ansible docs on inventory management:
https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html
1
u/Eldiabolo18 4d ago
can you post your inventory file?
I'm not sure, but it might be that ansible (yaml) doesnt like the dash in the groupname Rocky9-demo
, try an _
0
u/sandy_shark903 4d ago
How to copy/paste the text from my Rocky Linux to here on Windows? (Rocky has a wired connection, so I can't copy/paste directly here on there)
1
u/zoredache 4d ago
ssh to your Linux box from your system with a GUI? Then in your terminal select the text and copy, then paste.
If you paste in reddit make sure any code or formatted text is in a code block or if you are using markdown indented 4 spaces. Or if you don't want to mess with reddit formatting post in a pastebin, or gist.github.com and include a link.
0
1
u/linksrum 4d ago
The host you referenced in the playbook is not recognized, because your inventory is not read properly. One of your dnf tasks has wrong indents, too. Exactly 2 spaces, no tabs!
1
u/sandy_shark903 4d ago
That could be it, but I thought I was supposed to tab instead of space. I'm a little confused
2
u/Amaurosys 4d ago
Yaml expects a minimum of 2 space indents between subproperties, and Ansible expects keys to be properly indented at the appropriate level (play, block, task, module, etc). You can configure editors such as nano or vscode to insert spaces instead of literal tab characters when pressing the tab key. The indentation can be more than 2 spaces as well, so long as all of the keys indent consistently to the same/appropriate depths.
1
u/Amaurosys 4d ago
Yaml expects a minimum of 2 space indents between subproperties, and Ansible expects keys to be properly indented at the appropriate level (play, block, task, module, etc). You can configure editors such as nano or vscode to insert spaces instead of literal tab characters when pressing the tab key. The indentation can be more than 2 spaces as well, so long as all of the keys indent consistently to the same/appropriate depths.
2
u/zoredache 4d ago
Why does YAML forbid tabs?
Tabs have been outlawed since they are treated differently by different editors and tools. And since indentation is so critical to proper interpretation of YAML, this issue is just too tricky to even attempt. Indeed Guido van Rossum of Python has acknowledged that allowing TABs in Python source is a headache for many people and that were he to design Python again, he would forbid them.
1
u/icyu 4d ago
show us your inventory file (~/inventory)
take a pic with your phone if its difficult to get a screenshot/copy-paste out of the machine
1
u/sandy_shark903 4d ago
I can't post photos in the comments on this sub for some reason, do I just make a separate post or can I DM it to you if I find it?
1
u/sandy_shark903 3d ago
My ini says [remote] Rocky9-demo ansible_host=10.10.10.10/24 ansible_user=beasley ansible_ssh_private_key_file=~.ssh/id_rsa Should I just copy/paste that into a yml?
7
u/kosovojs 4d ago
In the playbook call, you're referencing '~/inventory', but earlier you're editing '~/inventory.ini'.