Not able to pass hostname as extra var from ansible tower

Hi there,

I want to pass hostname as extra variable from ansible tower to Playbook.how can i do this and how can i add this hostname to playbook?

Regards,
Abhi

Abhi,

Is this “hostname” the name of the host you want Ansible to manage? If so, why pass that through an extra variable rather than using the limit parameter?

In Ansible Tower, you have projects which define where your playbooks are stored and several more parameters such as credentials. Here’s what a typical project looks like.

Each project can have any number of job templates, where each template allows you to configure which hosts or Ansible host groups to run the playbook on (“Limit” in the red box below), what extra variables to use, what parameters to prompt for, etc. Here’s a typical job template.


Note that the nearly empty box below “Variables” would be where extra variables are defined. This job template doesn’t use any extra variables. When editing a job template, almost any of the fields shown above can be marked “Prompt on launch”, in which case you can override the default values at the time you launch the job.

Job templates can also be scheduled to run at regular intervals. Parameters which normally generate prompts can be filled in by the schedule just as if someone had manually started a job.

So, to address your question, “[H]ow can I add this hostname to [a] playbook?” If you really want to pass an extra variable called “hostname” that you can use in a playbook, you do that when you edit your job template. Be sure to check “Prompt on launch” if you want to override the default value when you run your job, like this:

In your playbook, you simply use the variable like any other:

- name: My task
  ansible.builtin.debug:
    msg: "My hostname variable is {{ hostname }}."

I hope this helps. Good luck.

i am creating jenkins pipe line to pass extra variable and want run playbook on host which i want to pass from jenkins…

(attachments)



Write the data to a file on the local host then delegate to the local host to read and delete the file, then continue with the playbook?

Mike

If you’re triggering an Ansible Tower or AWX job from Jenkins, presumably you are using the awx job_templates launch command, or the deprecated tower-cli command, both of which allow you to specify --limit. So I don’t see why you would try to do through --extra_vars what --limit already does.

That said, if you specify --extra_vars='{"hostname": "whatever.host."}' and in your playbook you have hosts: "{{ hostname }}", does that not work? You haven’t shown us anything you’ve tried yet, or what your invocation from Jenkins looks like, so we’re missing crucial details that would really help us help you.

Hi There,

I am running a SHell script to install application and need to automate using Ansible Playbook.
Below are majorly 2 tasks, which I am not able to figure out using Ansible playbook.

  1. When shell script is executed, it prompts for - “Are you sure you want to execute script [Yes/No]”?

  2. Secondly, shell script prompt for database password and confirm password.

Please suggest, how I can automate above tasks using Ansible playbook.

Regards,
Varun