Re: [ansible-project] pick the hostname dynamically from facts and match with inventory hostname and if matched then run the command

2018-03-07 Thread rraka1002
Thanks Kai.

On Wednesday, March 7, 2018 at 12:17:34 PM UTC+5:30, Kai Stian Olstad wrote:
>
> On Wednesday, 7 March 2018 06.31.27 CET rrak...@gmail.com  
> wrote: 
> > I'm looking for an idea to spill the hostname infromation geting from 
> facts 
> > and run the command if the matches the hostname provided in inventory. 
> > Saying that "myhostname" value should be picked & matched from inventory 
> > ones and get the IP of the hostname once matched to complete the command 
>
> A good start i this 
> https://docs.ansible.com/ansible/latest/playbooks_variables.html 
> 
>  
>
>
> > My Host inventory: 
> > 
> > test-host1 
> > test-host2 
>
> Try running ansible ad-hoc to see what facts you have available 
> ansible test-host1 -m setup 
> and/or 
> ansible localhost -m setup 
>
>
> > somecommand hostinfo=myhostname:IP_ADDRESS  
> > somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01 
> > 
> > Exaplaination: 
> > 
> > somecommand = Static Value 
> > hostinfo = Static Value 
> > myhostname = Should be the same as taken from inventory 
>
> {{ inventory_hostname }} 
>
>
> > IP_ADDRESS = Should be the IP of Hostname taken from invetory 
>
> There are different once, check with the ad-hoc command above. 
> One is {{ ansible_default_ipv4.address }} 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c0bef543-a91c-461f-9ac5-195fc3505ad1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] pick the hostname dynamically from facts and match with inventory hostname and if matched then run the command

2018-03-06 Thread Kai Stian Olstad
On Wednesday, 7 March 2018 06.31.27 CET rraka1...@gmail.com wrote:
> I'm looking for an idea to spill the hostname infromation geting from facts 
> and run the command if the matches the hostname provided in inventory.
> Saying that "myhostname" value should be picked & matched from inventory 
> ones and get the IP of the hostname once matched to complete the command 

A good start i this
https://docs.ansible.com/ansible/latest/playbooks_variables.html


> My Host inventory:
> 
> test-host1
> test-host2

Try running ansible ad-hoc to see what facts you have available
ansible test-host1 -m setup
and/or
ansible localhost -m setup


> somecommand hostinfo=myhostname:IP_ADDRESS 
> somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01
> 
> Exaplaination:
> 
> somecommand = Static Value
> hostinfo = Static Value
> myhostname = Should be the same as taken from inventory

{{ inventory_hostname }}


> IP_ADDRESS = Should be the IP of Hostname taken from invetory

There are different once, check with the ad-hoc command above.
One is {{ ansible_default_ipv4.address }}


-- 
Kai Stian Olstad

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3319467.MurqcspOtE%40x1.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] pick the hostname dynamically from facts and match with inventory hostname and if matched then run the command

2018-03-06 Thread rraka1002
I'm looking for an idea to spill the hostname infromation geting from facts 
and run the command if the matches the hostname provided in inventory.
Saying that "myhostname" value should be picked & matched from inventory 
ones and get the IP of the hostname once matched to complete the command 
My Host inventory:

test-host1
test-host2


somecommand hostinfo=myhostname:IP_ADDRESS 
somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01

Exaplaination:

somecommand = Static Value
hostinfo = Static Value
myhostname = Should be the same as taken from inventory
IP_ADDRESS = Should be the IP of Hostname taken from invetory
CMD_ARGS = Static Value ( like i mentioned CIC01)


- name: Ansible to get the resolv.conf output
  hosts: all
  remote_user: root
  gather_facts: True
  tasks:
  - name: runing re-image
shell: somecommand hostinfo=test-host1:xx.xx.xx.xx CIC01
 
register: named

  - name: Storing the remote Hosts Output locally 
lineinfile: create=yes dest=/opt/out.logs  line="{{ named.stdout }}"
delegate_to: 127.0.0.1

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b7767b1e-6800-4044-b301-44a89eb97fe7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.