# Ansible

Ansible is a configuration tool for automation. Ansible stage can configure the node machine with the configuration as per ansible playbooks.

### **Prerequisites:**

* To configure and use Ansible custom stage, you should have prior knowledge of spinnaker and spinnaker custom stage job.
* You must have a running spinnaker with a Kubernetes cluster account configured in it.\
  For more information on spinnaker custom job, refer [**here**](https://www.spinnaker.io/guides/operator/custom-job-stages/)**.**

### **Ansible custom stage architecture**

The Ansible custom stage architecture is shown in the image below:

![Ansible Custom Stage Architecture](https://lh3.googleusercontent.com/TXZ-XjIN8k3GuBDXSgyqaBaONiJI_J2qqdshtt2sCS8V9nXmWPilUPf6e8P6Vug6R3wFPju0BApr3wNJ9YZuIrM-nC3VuFXcHg2LDxg5v_U1OrlFgT2010s0GzlLjd5D7KAJvWUBNqfz-h5_ZIcjomY)

### **Configure Spinnaker with Ansible custom stage**

Execute the following steps to configure Spinnaker with Ansible custom stage.

1. Pass the credentials in k8s secrets where you will be setting the **Git Username, Git Password, Ansible Node user, and Password.** Use the following command to create the secret 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-secrets** is the name of secret in k8s which will be mapped in **orca-local.yml** in the manifest.

2\.  Once you run the above command, check whether the secret is created or not by using the following command:

```
# kubectl get secrets
```

{% hint style="info" %}
**Note:** Ansible stage configuration is stored in the **orca-local.yml** file in the path **/home/spinnaker/.hal/default/profiles** which is in Halyard pod. A dependent **configmap** with the name **ansible-config** is already configured with ISD.
{% endhint %}

### **Spinnaker UI Prerequisites for Ansible custom stage**

Spinnaker UI prerequisites for Ansible custom stage job are as follows:

1. **Ansible Playbook:** A sample playbook which creates a directory is shown below.

```
 - hosts: mynode
   tasks:
     - name: install apache2
       apt: name=apache2 update_cache=yes state=latest
       become: true
       become_user: root
     - name: start apache2
       service: name=apache2 state=started
       become: true
       become_user: root
```

{% hint style="info" %}
**Note:** Specify the host's name in the Playbook.
{% endhint %}

2\.  **Inventory file:** A sample inventory file is shown below.

```
[mynode]
137.116.114.86
```

{% hint style="info" %}
**Note:** Specify the host's name mentioned in the Playbook, and the server IP address.
{% endhint %}

### Execute Ansible Playbooks via the custom stage

Once the spinnaker is configured with Ansible Custom Stage, the "**Ansible-OPsMx"** stage should be available in the pipeline configuration.

To add “**Ansible-OPsMx**” stage to your pipeline follow the steps below:

1. Go to your application and click “**Pipeline builder**” and click “**Add Stage**” and then select “**Ansible-OPsMx**” stage from the drop-down menu as shown below.

![](https://lh3.googleusercontent.com/fWQOUGKDnXThv36dRaa-6Zp8Sudu3JS26lQ1iKE9VftqgKAPkwegYlz2RnFs3JYg2iyBHbXQ8YuW7R9PttcJGCJiO_aipY7TUvWJWlIV_EifNu0IeTd3xWszfogzUPeO0wK6nscAaMnPF1wV35hYKkk)

2\.  Now the configuration screen appears to provide the required parameters.

![](https://lh6.googleusercontent.com/rTtxwgHfYTjeAgvHBMtn2mUJ4yhWdlyb5Z_BYmxmMeQLmzw0nNoPPSG01kRBBVmRRtmb5jBUQVvjEvtlI3apzT6-qAgdnx_mi46rS_IUB7EOTSY_-DGbJZe0VWNQz03hZSbuMoYU4sSHRd89R1ygsL8)

**Enter the following parameters on the above configuration screen:**

* **Git repo:** Provide GitHub clone url without https\://&#x20;
* **Ansible file:** Provide the Ansible file location in the Git repo.&#x20;
* **Inventory File:** Provide the inventory file location in the Git repo.
