FAQ
Hi all
I need to trigger an action (generating a file using template) on another
server during a play run. Naturally I used delegation. However, if I use
variables like ansible_hostname I get the values from the *original* host.
That's indeed what I would expect on most cases, but is there a way to use
the "context" of the target server?

Example playbook:

- hosts: source
   tasks:
     - debug: var=ansible_hostname
       delegate_to: target

What I get:
TASK: [debug var=ansible_hostname]
********************************************
ok: [localhost] => {
     "ansible_hostname": "source"
}

What I want to get:
TASK: [debug var=ansible_hostname]
********************************************
ok: [localhost] => {
     "ansible_hostname": "target"
}


Thanks!

--
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+unsubscribe@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/8d6e27b7-2b3f-40f4-b4a3-8642465afc97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael DeHaan at Jul 30, 2014 at 12:07 pm
    There's no magic variable for this presently.

    If you'd like to work on it, or submit a feature idea ticket, a variable
    like "delegated_host" could be added.




    On Wed, Jul 30, 2014 at 5:22 AM, Hagai Kariti wrote:

    Hi all
    I need to trigger an action (generating a file using template) on another
    server during a play run. Naturally I used delegation. However, if I use
    variables like ansible_hostname I get the values from the *original* host.
    That's indeed what I would expect on most cases, but is there a way to use
    the "context" of the target server?

    Example playbook:

    - hosts: source
    tasks:
    - debug: var=ansible_hostname
    delegate_to: target

    What I get:
    TASK: [debug var=ansible_hostname]
    ********************************************
    ok: [localhost] => {
    "ansible_hostname": "source"
    }

    What I want to get:
    TASK: [debug var=ansible_hostname]
    ********************************************
    ok: [localhost] => {
    "ansible_hostname": "target"
    }


    Thanks!

    --
    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+unsubscribe@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/8d6e27b7-2b3f-40f4-b4a3-8642465afc97%40googlegroups.com
    <https://groups.google.com/d/msgid/ansible-project/8d6e27b7-2b3f-40f4-b4a3-8642465afc97%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    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 ansible-project+unsubscribe@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/CA%2BnsWgzeBNwvDbrtQFQ%2BPWJ8hM5S_xGe3PQ2X6gni9GRZ%3DverA%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupansible-project @
postedJul 30, '14 at 9:22a
activeJul 30, '14 at 12:07p
posts2
users2

2 users in discussion

Michael DeHaan: 1 post Hagai Kariti: 1 post

People

Translate

site design / logo © 2022 Grokbase