Recording generated template configurations

34 views
Skip to first unread message

Soren Olegnowicz

unread,
Aug 22, 2016, 11:05:54 AM8/22/16
to Ansible Project
Anybody know of a way to deploy a template to multiple servers, but have each configuration simultaneously centralized on another server? I do not want the servers speaking with each other, so synchronize would not really be an option. I would also prefer not to use fetch, as having the different configurations live on the main workstation would become too clunky too quickly.

Josh Smift

unread,
Aug 22, 2016, 11:45:58 AM8/22/16
to ansible...@googlegroups.com
SO> Anybody know of a way to deploy a template to multiple servers, but
SO> have each configuration simultaneously centralized on another server?

How about delegate_to?

- hosts: myservers

tasks:

- name: put foo on myservers
template:
src: foo.txt.j2
dest: /etc/foo.txt

- name: put foo for myservers onto centralserver
template:
src: foo.txt.j2
dest: "/srv/myservers/{{ inventory_hostname }}"
delegate_to: centralserver

That seems to work for me; it's not *simultaneous* simultaneous, but it's
in one playbook anyway. :^)

-Josh (j...@care.com)

(apologies for the automatic corporate disclaimer that follows)




This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

Brian Coca

unread,
Aug 23, 2016, 10:12:18 AM8/23/16
to ansible...@googlegroups.com
you can do in 1 task: 

- template: ....
  delegate_to: "{{item}}"
  with_items:
     - "{{inventory_hostname}}" # or ansible_host, depends on your inventory
     - central-host


----------
Brian Coca

Josh Smift

unread,
Aug 23, 2016, 5:37:43 PM8/23/16
to Ansible Project
SO> Thanks for the tip about delegation, donno how I have not used it yet.
SO> Do you have to change security settings when you do though? I am
SO> getting an SSH unreachable error on just that one delegate task (not
SO> the rest of them).

I think your Ansible control host would need to be able to SSH to "the
central server", so if it can't, that might give you an error like this. I
tested it in an environment where my control host can SSH to everything.

If "the central server" *is* the Ansible control host, and isn't allowed
to SSH to itself, then 'delegate_to: localhost' should work and not use
SSH at all.

Soren Olegnowicz

unread,
Aug 23, 2016, 6:50:53 PM8/23/16
to Ansible Project, j...@care.com
Thanks for the tip about delegation, donno how I have not used it yet. Do you have to change security settings when you do though? I am getting an SSH unreachable error on just that one delegate task (not the rest of them).

Brian Coca

unread,
Aug 24, 2016, 10:07:38 AM8/24/16
to ansible...@googlegroups.com
use `localhost` instead of the host name, unless you defined 'localhost' in your inventory it should avoid remote connections and use in the 'local' connection plugin.


----------
Brian Coca

Soren Olegnowicz

unread,
Aug 24, 2016, 1:51:46 PM8/24/16
to Ansible Project
Ok guys, I got it working. Thank you for all the help!
Reply all
Reply to author
Forward
0 new messages