Hi All,
Please be informed that, i am tying to create a POD and Namespace in Kubernetes via Ansible Playbook and push it from Jenkins.
I have wrote the yaml playbook and it is working fine if i run it from the Ansible server, but when i push it via jenkins getting an error.
In Jenkins i have used both Freestyle project.
---
- name: Creating a Pod
hosts: all
vars_prompt:
- name: pod_name
prompt: "Enter the POD Name to Create"
private: no
- name: ns_name
prompt: "Enter the Name Space to Create"
private: no
tasks:
- name: Creating a POD using Ansible
community.kubernetes.k8s:
api_version: v1
definition:
kind: Pod
metadata:
name: "{{ pod_name }}"
namespace: "{{ ns_name }}"
spec:
containers:
- name: "{{ pod_name }}"
image: nginx
- name: check the status of POD
command: kubectl get pods "{{ pod_name }}" -n "{{ ns_name }}"
register: pod
- name: print the POD status
debug: var=pod
- name: check the name space
command: kubectl get ns "{{ ns_name }}"
register: names
- name: Print the namespace status
debug: var=names
environment:
KUBECONFIG: /home/ansible/.kube/config
This is my ansible playbook. Kindly let me know how to setup the same in Jenkins.
Thanks a lot in advance.