Trigger Ansibile to run a playbook when GitHub Branch is merged

Hi Dev Group,

I am pretty new to Ansible and the Dev-Ops world.
I am working on an automated deployment project and I nearly have all the pieces together.

This is what I have done so far:

  • Installed Ansible on an Ubuntu server
  • Have Ansible pinging my Windows Server
  • Created a .yml playbook that connects to Windows Server and run a powershell script on that server

The main goal is:
-The Developer merges his/her changes from master branch to Pre-Production branch on GitHub
-When the merge is complete, this will trigger Ansible to run the playbook that connects to Windows server and executes the powershell script (ansible command = Ansible-playbook -i hosts run-powershell.yml)

Would anyone be able to point me in the right direction and provide some knowledge as to how I’d be able to achieve this?
Any help would be extremely apricated!!!

Kind Regards,
Dean

This is typical CI/CD.

You can use Jenkins for this.

Some knowledge might be learned from: https://www.katacoda.com

Best,
Karol

This is typical CI/CD.

You can use Jenkins for this.

Zuul CI is another option, especially if you want to run your actually
playbooks directly from it. It is a CI tool that used ansible for task
execution.

As an example, here is a working example of how to CD a set of playbooks
/ roles to a production services:

  https://ansible-network.softwarefactory-project.io/zuul/builds?job_name=windmill-config-deploy

you can look at any one of the 'SUCCESS' results, then log_url for
ansible logs.

[1] https://zuul-ci.org/

Hi Paul/Karol,

Thanks very much for your replies and insights!
So would you say that Jenkins would be the better tool to trigger an event based on what happens on GitHub?
Can you not add a WebHook to your GitHub Repo to trigger Ansible to run a playbook - is it possible?

Kind regards,
Dean

Hi Paul/Karol,

Thanks very much for your replies and insights!
So would you say that Jenkins would be the better tool to trigger an event
based on what happens on GitHub?
Can you not add a WebHook to your GitHub Repo to trigger Ansible to run a
playbook - is it possible?

Yes, jenkins / zuul / github actions will all be able to do this. Each
do it differently, but in the end will run a playbook on commit.