Remix.run Logo
SteveNuts 4 hours ago

The worst part of Ansible is data manipulation, what would be an easy dictionary operation in Python is a huge mix of lookups in Ansible.

Incredibly frustrating that the data you want is right there but you can't easily grab it.

gchamonlive 3 hours ago | parent [-]

If Jinja templating for data manipulation gets too complex or inconvenient, you can create your own module in ansible and use python code for data manipulation. But at this point you are better served with plain python which I think is where pyinfra should shine. I want to take a look though at how hard it is to implement your own module for it.

matthiaswh 3 hours ago | parent [-]

If you're doing data manipulation with server state, you would probably want to create a Fact[0]. This is a straightforward Python class.

If you're doing data manipulation locally you would simply write Python code.

Operations[1] are Python functions which execute (yield) commands which will be run on hosts.

That's the gist of what it takes to write custom modules for Pyinfra.

[0] https://docs.pyinfra.com/en/3.x/api/facts.html [1] https://docs.pyinfra.com/en/3.x/api/operations.html