0

I am trying to create a self service job template for our users through Ansible AWX , and want to restrict the users to mention the exact host detail where they want to run the job.

During testing I have noticed , If on the limit ( I have enabled prompt on launch ) one provides "*" , it executes on every node in the inventory , which is something I want to avoid and not let happen.

So let me explain you my requirement first

  1. User will login as themselves and run a job template . This job template needs to be run on node or pattern of node or group mentioned by that user.
  2. So I do not want to restrict execution of this playbook to a single group or multiple groups , I would like to promt user to provide hostname where they want to execute this playbook.

How I am trying to achieve this

  1. This is my playbook ( again just a example )
---
- hosts: "{{ target }}"
  gather_facts: no

  tasks:

  - name: Gather Hostname information
    shell: hostname
    register: hostname_result

  - debug: var=hostname_result.stdout_lines
  1. I have created one job template , with Survey to provide hostname where they want to run this job .

I see when we put * on that survey , this job template gets executed on all the hosts , which we do not want that.

Can anyone let me know how we can restrict users to put exact host details, not any regex or * ?

Appreciate your help.

1 Answers1

1

Below solution worked for me ....

---
- hosts: "{{ target }}"
  gather_facts: no

  tasks:

  - name: You cannot pass asterisk as target hosts
    meta: end_play
    when: target == '*'

  - name: Gather Hostname information
    shell: hostname
    register: hostname_result

  - debug: var=hostname_result.stdout_lines