0

I'm looking to trigger an Ansible Playbook via a POST request.

For example, I want to make Ansible listen on some port so that it can intercept a POST request, parse the JSON, and inject the values into the variables with the same key name.

So far, everywhere I look I see that Ansible can use REST APIs, but not act as an endpoint.

Is this possible? If not, any alternate suggestions will be much appreciated

Darrel Holt
  • 103
  • 6
  • There are CI/CD tools to do this, Jenkins, RunDeck, etc. Their API endpoints/hooks get POSTed and that runs the desired ansible playbook. – jscott Aug 29 '17 at 01:42

1 Answers1

1

I want to make Ansible listen on some port so that it can intercept a POST request

You can't make Ansible listen on a port (yet "intercept"), because Ansible (called ansible as well as ansible-playbook) is just a user-executable Python script.

Write a service component listening on a designated port and execute the ansible-playbook command from it.

parse the JSON, and inject the values into the variables with the same key name.

You can pass the JSON object as a variable (dictionary) directly to ansible-playbook as an argument to the command.

techraf
  • 4,243
  • 8
  • 29
  • 44
  • I'll accept your answer if you explain what you mean by "Service Component". I assumed you meant something like @jscott mentioned above, but using a CI or CD tool wouldn't be writing my own. – Darrel Holt Aug 29 '17 at 15:35
  • component = a piece of software; service = running not in user space, but in background; don't expect CI/CD tools to wait for your POST requests by default; you would probably have to write the same thing whatever tool you choose. – techraf Aug 29 '17 at 22:05
  • Unfortunately, I work for a large company so simply writing some software to listen for a POST request and running it on their servers isn't going to be allowed, nor do I have the time to do that. Thank you though, for pointing me in the right direction. – Darrel Holt Aug 29 '17 at 22:07