|
| 1 | +# Ansible Runner |
| 2 | + |
| 3 | +Ansible Runner Task allows running the Ansible Playbooks using the [ansible-runner](https://ansible-runner.readthedocs.io/) tool. |
| 4 | + |
| 5 | +The latest versions of ansible-runner requires [`community.general`](https://github.com/ansible-collections/community.general) to be installed from ansible-collections. |
| 6 | + |
| 7 | +## Creating the Task |
| 8 | + |
| 9 | +Create the Task and other resources: |
| 10 | + |
| 11 | +```shell |
| 12 | +kubectl apply --filename https://api.hub.tekton.dev/v1/resource/tekton/task/ansible-runner/0.2/raw |
| 13 | +``` |
| 14 | + |
| 15 | +Verify the created tasks: |
| 16 | + |
| 17 | +```shell |
| 18 | +tkn task ls |
| 19 | +``` |
| 20 | + |
| 21 | +## Parameters |
| 22 | + |
| 23 | +* **project-dir**: The ansible-runner private data dir |
| 24 | +* **args:**: The array of arguments to pass to the runner command (_default:_ --help) |
| 25 | +* **user-home**: Absolute path to the user's home directory. (_default:_ /tekton/home) |
| 26 | +* **workspaces_ssl_ca_file**: file name of ca bundle. (_default:_ ca-bundle.crt) |
| 27 | + |
| 28 | +## Workspaces |
| 29 | + |
| 30 | +* **runner-dir**: A [workspace](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md) to hold the `private_data_dir` as described in https://ansible-runner.readthedocs.io/en/latest/intro.html#runner-input-directory-hierarchy[Runner Directory] |
| 31 | +* **ssl-ca-directory**: A optional [workspace](https://github.com/tektoncd/pipeline/blob/main/docs/workspaces.md) to hold the ca_certs for custom certificate authorities. |
| 32 | + |
| 33 | +## Platforms |
| 34 | + |
| 35 | +The Task can be run on `linux/amd64` platform. |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +The TaskRun uses the repository https://github.com/vinamra28/tektoncd-ansible-runner-example, that houses some example playbooks. |
| 40 | + |
| 41 | +All the examples will be run in namespace called `funstuff`. Create the namespace and shift the context to it: |
| 42 | + |
| 43 | +```shell |
| 44 | + kubectl create ns funstuff && \ |
| 45 | + kubectl config set-context --current --namespace=funstuff |
| 46 | +``` |
| 47 | + |
| 48 | +### Create the PVC and clone example sources |
| 49 | + |
| 50 | +```shell |
| 51 | +kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/git-clone/0.5/raw \ |
| 52 | + -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/ansible-runner/0.2/support/playbooks-pvc.yaml |
| 53 | +``` |
| 54 | + |
| 55 | +Do the git clone of the examples repository: |
| 56 | + |
| 57 | +```shell |
| 58 | +tkn task start git-clone \ |
| 59 | + --workspace=name=output,claimName=ansible-playbooks \ |
| 60 | + --param=url=https://github.com/vinamra28/tektoncd-ansible-runner-example \ |
| 61 | + --param=revision=master \ |
| 62 | + --param=deleteExisting=true \ |
| 63 | + --showlog |
| 64 | +``` |
| 65 | + |
| 66 | +### Create the Service Account |
| 67 | + |
| 68 | +As we will do get, list and create on the namespace, lets use a service account that has right RBAC: |
| 69 | + |
| 70 | +```shell |
| 71 | +kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/ansible-runner/0.2/support/ansible-deployer.yaml |
| 72 | +``` |
| 73 | + |
| 74 | +### Run Tasks |
| 75 | + |
| 76 | +List the pods of `kube-system` namespace: |
| 77 | + |
| 78 | +```shell |
| 79 | + tkn task start ansible-runner \ |
| 80 | + --serviceaccount ansible-deployer-account \ |
| 81 | + --param=project-dir=kubernetes \ |
| 82 | + --param=args=-p,list-pods.yml \ |
| 83 | + --workspace=name=runner-dir,claimName=ansible-playbooks \ |
| 84 | + --showlog |
| 85 | +``` |
| 86 | + |
| 87 | +### Create Deployment |
| 88 | + |
| 89 | +Create a deployment in `funstuff` namespace: |
| 90 | + |
| 91 | +```shell |
| 92 | + tkn task start ansible-runner \ |
| 93 | + --serviceaccount ansible-deployer-account \ |
| 94 | + --param=project-dir=kubernetes \ |
| 95 | + --param=args=-p,create-deployment.yml \ |
| 96 | + --workspace=name=runner-dir,claimName=ansible-playbooks \ |
| 97 | + --showlog |
| 98 | +``` |
| 99 | + |
| 100 | +### Create Service |
| 101 | + |
| 102 | +Create a service in `funstuff` namespace: |
| 103 | + |
| 104 | +```shell |
| 105 | + tkn task start ansible-runner \ |
| 106 | + --serviceaccount ansible-deployer-account \ |
| 107 | + --param=project-dir=kubernetes \ |
| 108 | + --param=args=-p,create-service.yml \ |
| 109 | + --workspace=name=runner-dir,claimName=ansible-playbooks \ |
| 110 | + --showlog |
| 111 | +``` |
0 commit comments