How to Create Ansible Custom Job in Spinnaker

What you’ll learn:

  1. How to configure and set up Ansible stage in Spinnaker as a custom stage job

  2. How to execute Ansible playbooks through.

Prerequisites:

  1. Understanding of spinnaker and spinnaker custom job.

  2. Running spinnaker with Kubernetes cluster account configured in it.

Get detailed information about Spinnaker Custom Job.

Ansible Custom Stage Architecture:

The custom stage architecture is shown in the image below:

Custom Stage Architechture

Follow the steps given below:

  1. Create the configmap with the name ansible-config which will be mapped in orca-loca.yml. The configmap name can be anything as per your choice. In this document we are using the name as ansible-config. configmap is available here.

Note: mention your namespace in configmap.

2. Apply the configmap as shown below:

# kubectl apply -f configmap

After applying, check whether the configmap is created using the command below:

# kubectl get cm

3. Pass the credentials in k8s secrets where you will be setting the git username, password, Ansible node user and password. Use the following command to create the secrets and add appropriate credentials:

kubectl create secret generic ansible-secrets --from-literal=gitusername=<USERNAME> --from-literal=gitpassword=<PASSWORD> --from-literal=nodeuser=<USER> --from-literal=userpassword=<USERPASSWORD> -n <namespace>

In the above command, ansible-secret is the name of secrets in k8s will be mapped in orca-local.yml in manifest. Here we are using secretname as ansible-secret, you can use any name as per your choice.

Once done, check whether it is created or not using the following command:

# kubectl get secrets

4. Create orca-local.yml file in /home/spinnaker/.hal/default/profiles which is in Halyard pod. If it already exists you can add the content below except the first three lines. orca-local.yml is available here.

Apply the changes to reflect in Spinnaker UI using the following command:

# hal deploy apply

Spinnaker UI Prerequisites needed for Ansible job:

Ansible playbook - For sample playbook which creates a directory. Sample playbook is available here.

Note:- Specify hosts name in the playbook.

Inventory file - For sample inventory file. Sample inventory is available here.

Note:- Specify hosts name mentioned in Playbook and server IP.

Follow the steps given below:

  1. Create new pipeline and create a stage here where ansiblejob is located in the drop-down list and select the ansibleJob as shown below:

2. It will ask for the repo URL, ansible file location and inventory file. Mention the entire file path from the repo and the other details. Refer to the image below:

3. Save and run the pipeline.