9

Ansible AWX requires inventories to be entered in yaml or json format.

When you start learning ansible, you may take the choice to start off with your inventory in ini format.

https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

Is it possible to convert between formats?

RichVel
  • 7,030
  • 6
  • 32
  • 48
user1717259
  • 2,717
  • 6
  • 30
  • 44
  • I would be very interested to know in which version of AWX this limitation has been made... since we currently use AWX with about a dozen inventories in `ini` format. I'd better make sure we modify them before we upgrade. – Zeitounator Nov 04 '19 at 10:30

2 Answers2

19

Example given here

https://evrard.me/convert-ansible-inventories-with-ansible-inventory-cli

ansible-inventory -i inventory.ini -y --list > inventory.yaml

The -y flag gives yaml output. Omitting the flag gives json.

user1717259
  • 2,717
  • 6
  • 30
  • 44
  • 2
    That works for a simple inventory, but if you are using `group_vars` directories it will 'flatten' those group vars into the output YAML file, so you would need to edit them out. – RichVel Nov 04 '19 at 09:13
  • @RichVel just copy your inventory to another folder first to ignore the group vars – ataraxis Aug 10 '22 at 20:44
1

There is a converter written in python here.

https://github.com/appuio/ansible-ini2yaml

user1717259
  • 2,717
  • 6
  • 30
  • 44
  • 2
    Tried this and it does work quite well - handles the slightly unusual Ansible format within the INI file sections, and generates equivalent YAML. Gives a warning from the `pyyaml` package, and Python 2.7 only but probably not hard to port to Python 3. – RichVel Nov 04 '19 at 09:42