Command to test and debug ansible-pull code locally

I’m writing a playbook to configure my personal machine and I want to use ansible-pull to do that.
What I need is a command to test my playbook without committing the changes, push and then run ansible-pull. I need something more straightforward, like something that will test the code locally quicker. I came up with this little line, but I don’t know if it’s a good representation of what happens when I invoke ansible-pull locally.

#!/bin/bash
ansible-playbook local.yml -i "localhost,"

It seems simple, but I’m afraid maybe I’m not seeing something and this code could have catches and doesn’t run equal to ansible-pull.

Depends on what you’re doing, maybe you can run your ansible-pull command inside a container (podman, docker…).

This will test what ansible-pull does after it ‘preps’ things. If using a git repo to serve the playbook, you would also need a git action that checkout/updates the repo locally before execution.

@bcoca Thanks for the tip, but I just need to test the code itself during development. Do you see any caveats in my code (besides the one you previously mentioned)?

BTW, I added a -c local so it will always run locally, since the goal is debug. I found that analyzing the pull.py source file. Underneath it seems to execute an ansible-playbook command with quite opinionated options.

That should be enough

Thanks @bcoca. One last question: what is the function of --limit option in this scenario? For me, it’s configured to localhost,glados,127.0.0.1 (glados is my machine’s name). I wonder why it’s necessary to set the limit even setting --inventory as localhost,.

IIRC because you can pass alternate inventories to ansible-pull

1 Like