copy each confi file on each server

20 views
Skip to first unread message

alex podolin

unread,
Jul 8, 2016, 10:34:55 AM7/8/16
to Ansible Project
Hi all. I hope anybody can help me.
I have a few servers called SERVER-01 SERVER-02....SERVER-N
and *.conf files for this servers
# tree roles/put_cameras/files/nginx/
roles/put_cameras/files/nginx/
├──SERVER-01
│   ├── config01.conf
│   ├── config02.conf

├── SERVER-02
│   ├── config01.conf
│   ├── config02.conf
.......
├── SERVER-N
│   ├── config01.conf
│   ├── config02.conf

can you tell me, how to put files from  files/nginx/SERVER-01/{*.conf} to SERVER-01 /etc/nginx; files/nginx/SERVER-02/{*.conf} to SERVER-02 /etc/nginx; files/nginx/SERVER-N/{*.conf} to SERVER-N /etc/nginx; 
I think i can do it throw loops? but i don't understand how...




Mark Janssen

unread,
Jul 11, 2016, 6:35:01 AM7/11/16
to ansible...@googlegroups.com
Something like this ? (directly copied from a play I use... not tweaked to your settings ;) )


#!/usr/bin/env ansible-playbook
# Fetch files from remote hosts

---

- hosts: all
  gather_facts: yes
  vars:
    outputdir: "data"
    infofiles:
      - /etc/krb5.conf
      - /etc/resolv.conf
      - /etc/sysconfig/network-scripts/ifcfg-*
      - /etc/sysconfig/network-scripts/route-*
      - /etc/sudoers.d/*
  become: yes
  tasks:

  - name: Fetch filenames
    shell: "find {{infofiles|join(' ')}} -type f"
    register: filenames
    ignore_errors: yes
    tags:
      - filenames
      - fetch

  - name: Fetch config-files
    fetch: src="{{item}}" dest="{{outputdir}}/"
    with_items:
      - /etc/passwd
      - /etc/redhat-release
      - "{{filenames.stdout_lines}}"
    tags:
      - fetch


--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/860d76f6-59b4-43b9-9a32-d74fde8b0f3f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mark Janssen  --  maniac(at)maniac.nl
Unix / Linux Open-Source and Internet Consultant
Maniac.nl Sig-IO.nl Vps.Stoned-IT.com

Reply all
Reply to author
Forward
0 new messages