I'm trying to create a playbook to run a k8s job with ansible, but I have timeout problems.
Ansible 2.8.1 Kubernetes 1.11
tasks:
- name: Execute1
k8s_raw:
state: present
host: api-br-k8s-k8s-XXXXXX-001100.sa-east-1.elb.amazonaws.com
verify_ssl: no
username: username
password: "password"
definition: "{{ lookup('template', 'files/job.yml')| from_yaml }}"
The job.yml is ok, I'm tested with kubectl -f job.yaml apply
. The Host, User and Pass is ok, I'm tested in browser.
I expect the output is the creation of a job from the .yml file
As @Vinicius Peres mentioned in the comment, the issue has been solved by applying command lines within Ansible shell module, deserving the same result as was expected to get from playbook through k8s_raw module.
- name: Container Exec 3 - Verify Job and Exec Job
shell: docker exec job-backup-portal bash -c 'VERIFY_JOB=$(kubectl -n production get job| grep -c backup-portal-site); [[ ${VERIFY_JOB} -ge 1 ]] && kubectl -n production delete job backup-portal-site || kubectl -n production -f /home/job.yml apply'
Match wiki
flag to this answer as potential workaround solution.