This project showing how to provision, deploy and run script as service on both Linux and Windows.
- .gitignore - Git ignore file.
- ansible.cfg - Ansible configuration to configure the inventory details
- host-monitor.service - Linux based service file for configuring the service
- hosts - Inventory file for Ansible to have the server details where the service will be deployed
- Jenkinsfile - Jenkins pipeline file to create the service on both windows and linux
- playbook.yml - Ansible playbook to deploy copy the files and to create the service on both windows and linux
- process.py - Simple python script to print hostname and date stamp
- README.md - This file
Github -> Jenkins with Ansible (on linux) -> Target (Windows/Linux Server)
Ansible can be installed on a different server like below but for this project the above flow is used by having Jenkins and Anisble on same linux server.
Github -> Jenkins (on linux) -> Ansible (linux) -> Target (Windows/Linux Server)
- Nothing required
- Install Git for checkout repo during build.
- Install python
sudo yum install python3 -y
as it required for Ansible. - Install Ansible
sudo yum install python3 -y
and add ansible bin directory/usr/local/bin
to Environment variablePATH
- Make sure the SSH keys used to connect linux target servers is under
/var/lib/jenkins/.ssh/
with owner as jenkins for user and group with required permission. - Create pipeline to use Jenkinsfile file from Github repo.
- Add credentials to Jenkins if the repo is private and configure it in pipeline.
- Configure the pipeline to have listed parameters to be passed on each build.
- Install WinRM which is used by Ansible for connecting to Windows. You can use
sudo pip3 install pywinrm
for linux host.
Parameter type: Choice, Parameter Name: host, Paramater Value: ['linux','windows']; // This is deciding which target the pipeline should be executed. It can be either windows or linux, but not both.
Parameter type: Credentials, Parameter Name: git_credential, Paramater Value: <User name and password of git repo>; // Configured it in Jenkins
Parameter type: String, Parameter Name: git_branch, Paramater Value: <Branch of git repo>; // master
Parameter type: String, Parameter Name: git_repo_url, Paramater Value: <Clone URL of git repo>;
Parameter type: Text, Parameter Name: host_details, Paramater Value: <[linux]\nlinux1.com\nlinux2.com \nOR\n [windows]\nwin1.com\nwin2.com>;
- No seperate configuration for Ansible as we covered it in above section.
- No seperate configs but esnure the SSH connectivity from Jenkins
- Create new user name and password with Admin rights which will be used to connect by ansible to connect and run playbook.
- Configure WinRM if not already done. Details on how to configure is available in https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#winrm-setup.
- Implementation is simple. Change the target server details on hosts file. For Linux server add hostname below [linux] and windows server below [windows].
Once done push it to repo and configure it to consumed by Jenkins pipeline to read the file
Jenkinsfile
. Ensure the other parameter values are also given if default value are not set for those.
- User/SSH details for bot linux and windows hosts are already configured.
- Linux user used here is
ec2-user
- Windows user used here is
Test
- Script and log will be available in
/app/
for Linux targets - Script and log will be available in
C:\Process\
for Linux targets - Linux service name
host-monitor.service
- Windows service name
Hostname Monitor