Requirement is to integrate TFS release process with Ansible so that we can run Ansible playbook as a task in release.
I have created below architecture to implement it. In this architecture, TFS release task will send request to Ansible control machine (LINUX) to run the playbook on one of the target machine. Target machine could be LINUX based or Windows based. For LINUX, Ansible uses SSH for pushing the commands and for Windows, Ansible uses WinRM for pushing the commands.
To setup the above architecture, follow the below steps –
- Configure TFS agent on one of the build/release servers.
- Download and configure Ansible plugin from the MS Marketplace. Link – https://marketplace.visualstudio.com/items?itemName=ms-vscs-rm.vss-services-ansible
- Create SSH based service endpoint in TFS. It will be used to connect to the Ansible Control machine. SSH Connection Window
- Enable/configure WinRM on the target Windows machine. To automate the setup of WinRM, you can run the examples/scripts/ConfigureRemotingForAnsible.ps1 script on the remote machine in a PowerShell console as an administrator.
- Create release definition and add “Run Playbook” task in it and configure as shown below –
Steps to be done on the Ansible control machine –
- Create the below structure. It has “group_vars” folder for holding all the group variables.
- Below is the content of web.yml. Ansible_user should be the local admin on the server. Note – Do not use “ignore” for ansible_winrm_server_cert_Validation” in production.
- Below is the content of inventry.yml. It will hold all target host name/IP address.
- Below is the content of the main playbook –
- To test the above playbook, run the below command - ansible-playbook FirstPlayBook.yml -i inventry.yml –vvv
- If the above playbook has executed successfully, TFS release task is ready to use. Run the TFS release and it should be completed successfully. It will generate log as shown below –
——-End of Article——-