ansible / awx-resource-operator

41 stars 34 forks source link

How to run jobs from the operator #44

Closed fatimazahrae2104 closed 1 year ago

fatimazahrae2104 commented 3 years ago

Recently I deployed Ansible AWX on my Openshift cluster, and it works fine, and I also deployed the Ansible automation platform resource operator from the OperatorHub, Then I used the Ansible JobTemplate API instance, where I mentioned all the informations of the JobTemplate i have already on my AWX.

I want to know how to launch the JobTemplate from the Operator, can anyone help me how it works?!!

Thanks in advance!

This is my JobTemplate yaml.

image

mikeshng commented 3 years ago

Hi, based on my understanding of your question: you want to launch a job instance for the job template you created?

fatimazahrae2104 commented 3 years ago

Hello @mikeshng, First of all thank you for your immediate response.

image

image

However my Inventory contains localhost as a unique host with Prompt on launch checked, and I don't have extra vars so I deleted this section.

image

mikeshng commented 3 years ago

Hi, this is working as expected for now.

The AnsibleJob CR triggers the job launch and gives you an overview of the result of the tower job. So if you do: kubectl -n awx get AnsibleJob demo-job -o yaml you should see the result of the job execution. For example, if there was an error, it will show

status:
  ansibleJobResult:
    changed: true
    failed: false
    status: error
    url: >-
      https://ansible-tower-web-svc-tower.apps.-redacted-.com/#/jobs/playbook/5

Users are meant to use that url and actually see the all the details of the job execution. Maybe you can make a feature request regarding displaying the output of the actual tower job execution log in Kubernetes log some where?

As for the secret, it should be fine since you were able to create a job and communicate with the awx/tower successfully.

fatimazahrae2104 commented 3 years ago

Actually, it's not very important for me to display the AnsibleJob execution log using Kubernetes as long as I can see it on tower, but I just thought that I didn't follow the right steps to make them appear in kubernetes, but now it's fine :) .

mikeshng commented 3 years ago

But what if I want to re-execute the Job Template, should I create another Ansible Job to do So?

Yep. Each AnsibleJob represent an instance of Job on awx/tower. It behaves similar to how awx/tower keeps a list of already ran jobs. In short, to re-execute use https://github.com/ansible/awx-resource-operator/blob/devel/deploy/crds/tower.ansible.com_v1alpha1_joblaunch_cr.yaml#L4 which should give you another instance with a unique enough suffix.

your 2nd question

The operator does not need to communicate with your "target hosts", it only needs to talk to the tower. The tower is responsible for communicating with the various hosts that it's managing. In short, without using the operator, first make sure the Job Template can be executed successfully using your AWX/Tower instance only. Then afterwards, you can use the operator to trigger those jobs.

fatimazahrae2104 commented 3 years ago

Hello @mikeshng

Ok, so the role of this operator is only to trigger the jobs created on AWX, nothing else, is it?

mikeshng commented 3 years ago

Right, as of now, this operator is only responsible for managing job templates and creating job instances for job templates.

See the CRDs and examples that this operator deals with here: https://github.com/ansible/awx-resource-operator/tree/devel/deploy/crds

fatimazahrae2104 commented 3 years ago

Ok, I got it now.

Thank you so much for the help 👍

the-it-jaeger commented 1 year ago

It would seem all questions have been answered. I would suggest /close

@fatimazahrae2104 would you confirm you are satisfied and close this issue?