Passing nodenames as an argument in a command

20 views
Skip to first unread message

Parth Patel

unread,
Sep 27, 2017, 12:12:36 PM9/27/17
to Ansible Project
I am new to ansible. This is what I am trying to run,

on poc1 run,

client -a 8101 -h localhost 'fabric:ensemble-add -f poc2 poc3'


I want to run above command on "poc1" node passing arguments as "poc2" and "poc3". How do I get that using hostvars or groups from inventory file.  


I have tried this but It didn't work.

inventory file :

[testnodes]
poc1
poc2
poc3



YML,

---
 - hosts: testnodes[0]
   remote_user: test
   become: yes
   become_method: sudo
   
   tasks:

    - name: Add fabric Ensemble
      shell: ./client -a 8101 -h localhost 'fabric:ensemble-add -f {{ groups['fusehosts'][1:] }} '

      args:
        chdir: /opt/jboss-fuse-6.3.0.redhat-187/bin/



Kai Stian Olstad

unread,
Sep 27, 2017, 1:05:20 PM9/27/17
to ansible...@googlegroups.com
On 27. sep. 2017 18:12, Parth Patel wrote:
> I am new to ansible. This is what I am trying to run, on poc1 run,
>
> client -a 8101 -h localhost 'fabric:ensemble-add -f poc2 poc3'
>
> I want to run above command on "poc1" node passing arguments as "poc2" and
> "poc3". How do I get that using hostvars or groups from inventory file.
>
> I have tried this but It didn't work.
>
> inventory file :
>
> [testnodes]
> poc1
> poc2
> poc3
>
> ---
> - hosts: testnodes[0]
> remote_user: test
> become: yes
> become_method: sudo
>
> tasks:
>
> - name: Add fabric Ensemble
> shell: ./client -a 8101 -h localhost 'fabric:ensemble-add -f {{
> groups['fusehosts'][1:] }} '


You are using fusehosts and not testnodes as you inverntory has.
You can use one of these

{{ groups.testnodes | difference([inventory_hostname]) | join(' ') }}"
{{ groups['testnodes'][1:] | join(' ') }}


--
Kai Stian Olstad

Parth Patel

unread,
Sep 27, 2017, 1:55:24 PM9/27/17
to Ansible Project
Thanks a lot ! It worked
Reply all
Reply to author
Forward
0 new messages