Try to put quotes around that ("{{ inventory_hostname }}") so it's
probably interpreted by Jinja2.

A working example:

---
- hosts: localhost
  gather_facts: no
  tasks:
    - debug:
        msg: "{{ inventory_hostname }}"


$ ansible-playbook -i "localhost," play.yml 

PLAY [localhost]
************************************************************** 

TASK: [debug ]
**************************************************************** 
ok: [localhost] => {
    "msg": "localhost"
}

PLAY RECAP
******************************************************************** 
localhost                  : ok=1    changed=0    unreachable=0   
failed=0   


On Tue, 09 Jun 2015 11:48 -0700, richard kappler <[email protected]>
wrote:
> Actually, I'm reading Ansible: Up and Running, and under
> inventory_hostname 
> it says I did it right, yet when I ran the playbook, I got an error
> saying 
> inventory_hostname wasn't defined. I think maybe I should start a new 
> thread.
> 
> On Tuesday, June 9, 2015 at 2:42:53 PM UTC-4, richard kappler wrote:
> >
> > I see what you're saying. Tried to put it into play, but I'm obviously 
> > still missing some fundamental knowledge. How do I call the variable?
> >
> > I tried:
> > - replace:
> >     dest=<filename>
> >     regexp='placeholder'
> >     replace={{ inventory_hostname }}
> >     backup =no
> >
> > and it wouldn't work. I can get the file to work, as an experiment in 
> > place of {{ inventory_hostname }} I put {{ ansible_eth0.ipv4.address }} and 
> > the replace worked, putting the IP address of the target system where 
> > 'placeholder' used to be, so I've got that part down, but calling variables 
> > I haven't got a handle on yet. 
> >
> > Off to do more reading. Thanks for the help Giovanni!
> >
> > regards, Richard
> >
> >
> >>
> >> I think you should try using the inventory_hostname variable for that. 
> >> It'll return those serverXX names you defined. 
> >>
> >> If you need more vars per host, I would use host_vars. 
> >>
> >>
> >> https://docs.ansible.com/playbooks_best_practices.html#group-and-host-variables
> >>  
> >>
> >> Giovanni 
> >>
> >
> 
> -- 
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a7383975-1dcc-4fac-9ee1-e8ad0b9c62d4%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1433878170.3074048.291133281.2E7D143B%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to