News for hackers. Stuff that matters.
Re:Ansible 101 by Jeff Geerling – new series on YouTube by BiteCode_dev on Sunday March 22, 2020 @05:38PM (#22658941)
Keyword being "friendly".

See, if hello world is:

    - name: Hello Ansible
    hosts: ansibleclient01.local
    tasks:
        - name: Copy '/tmp/testfile.txt' into 'hello world'.
        copy:
            content: hello worldn
            dest: /tmp/testfile.txt
Then it would become:

    from icandream import playbook
    pb = playbook("Hello Ansible", hosts=["ansibleclient01.local"])
    with db.define_task(Copy '/tmp/testfile.txt' into 'hello world') as task:
        task.copy(content="hello worldn", dest="/tmp/testfile.txt)
Instant benefits:

- Python interpretter is very good at telling you error messages.

- You get an exception system, stack trace and a debugger for free

- The entire python tooling ecosystem, including full monthy IDE support, linters and formaters, is at your disposal

- Any more complex example is going to be much cleaner than the yaml version, exponentially. And no need to live in the "yaml/python module" dichotomy to keep PB clean.

- No need to reinvent the wheel. Python has elegant import, namespaces, ways to pass data around, conditionals, etc.,

- You can import Python libs. Event if it's just for declarative stuff like pendulum, appdirs..

The only cons are:

- idempotence needs to be enforced culturally. It's already the case for people writing the module behind the scene, and a good API + some warning tricks would be enough IMO.

- can't read the files outside of Python. But nobody does it anyway, and we can always let the Python files output the yaml representation if needed.

Now I don't hold my breath because it's a lot of work and the ansible community usually don't like the idea at all, and I'm not willing to do it. Fair is fair.

There are no comments on this comment yet.