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.
On Sunday, March 19, 2023 at 1:00:54 PM UTC-4 Linux Study wrote:
> i am creating jenkins pipe line to pass extra variable and want run
> playbook on host which i want to pass from jenkins...
>
> On Sat, 18 Mar 2023, 19:35 Todd Lewis, <[email protected]> wrote:
>
>> 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.
>>
>> On 3/18/23 5:09 AM, Linux Study wrote:
>>
>> 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
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAEcjLFwUoRLfQG7Yy4NVpfjuwEAL4bqHwmFo-OijUFgmxLD0ng%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/CAEcjLFwUoRLfQG7Yy4NVpfjuwEAL4bqHwmFo-OijUFgmxLD0ng%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>>
> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/946107ed-d83f-c8d3-d641-5b1e65ace095%40gmail.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/946107ed-d83f-c8d3-d641-5b1e65ace095%40gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/21614854-51c0-4df5-9f10-6bda2136c845n%40googlegroups.com.