delegate_to from inventory? copy between remote hosts

making a playbook to set up ceph clients, so want to transfer a client key from server (a monitor host) to client. since the server and client are both far away and sitting next to each other, id like to copy between them, so of course, i tried

  • name: make sure the client key is in place
    copy: src=/etc/ceph/ceph.client.admin.keyring dest=/etc/pve/priv/ceph/rbd.keyring
    delegate_to: mons[0]

and to make sure it knew what i wanted,

$ ansible mons[0] --list-hosts
c1

ran the playbook and got this,

failed: [proxbox → mons[0]] => {“failed”: true}
msg: could not find src=/etc/ceph/ceph.client.admin.keyring

(maybe it was looking on the local filesystem?)

then i tried synchronize, as suggested here, http://stackoverflow.com/questions/25505146/how-to-copy-files-between-two-nodes-using-ansible
but got this,

fatal: [proxbox → mons[0]] => SSH Error: ssh: Could not resolve hostname mons[0]: nodename nor servname provided, or not known

does delegate_to not use the inventory?

Try wrapping your mons variable in {{ }} like this…

delegate_to: {{ mons[0] }}

I’m pretty sure without them your variable is being interpreted as a literal.

quote it

delegate_to: "{{ mons[0] }}"

Right. Thanks bcoca. Always forget that one until I run.