我正在尝试使用同步模块备份文件。目前,我已经为测试硬编码了目录,但我需要它是模式。
Ansible版本2.9
我需要将其通用于版本*,而不是我目前拥有的版本2。这是我的剧本。
--- - name: Backup configurations from all confluent components hosts: all tasks: - set_fact: inv_host_path: "/tmp/synctest/properties-backup/{{ inventory_hostname }}/" systemd_path: "/etc/systemd/system/" zookeeper_data_path: "/var/lib/zookeeper/version-2/" - name: Cretate directories. file: path: "{{ item }}" state: directory delegate_to: localhost loop: - "{{ inv_host_path }}{{ systemd_path }}" - "{{ inv_host_path }}{{ zookeeper_data_path }}" - name: synchronise files in one loop synchronize: src: "{{ item.src }}{{ item.syncpattern }}" dest: "{{ inv_host_path }}{{ item.dest }}" rsync_path: "sudo rsync" mode: pull delegate_to: localhost register: sync_output loop: - { src: "{{ systemd_path }}", dest: "{{ systemd_path }}", syncpattern: 'confluent*' } - { src: '/etc/', dest: '/etc/', syncpattern: 'confluent*' } - { src: '/etc/', dest: '/etc/', syncpattern: 'kafka' } # - { src: "{{ zookeeper_data_path }}", dest: "{{ inv_host_path }}{{ zookeeper_data_path }}", syncpattern: 'snapshot*.*' } # check if directory exists - name: check if directory exists stat: path: "{{ zookeeper_data_path }}" register: zookeeper_data_dir_stat - name: synchronise files in second loop synchronize: src: "{{ item.src }}{{ item.syncpattern }}" dest: "{{ item.dest }}" rsync_path: "sudo rsync" mode: pull delegate_to: localhost register: sync_output loop: - { src: "{{ zookeeper_data_path }}", dest: "{{ inv_host_path }}{{ zookeeper_data_path }}", syncpattern: 'snapshot*.*' } when: zookeeper_data_dir_stat.stat.exists