0

我需要的只是标题,例如我想知道如何做这样的事情:

---
- hosts: ansible-clients

  tasks:
    - name: Fetch source list from clients
      fetch: src=/etc/apt/sources.list
             dest=/tmp/allnodes.sourcelist

或以简单的方式

echo remote@/etc/apt/sources.list >> local@/tmp/allnodes.sourcelist

我可以在本地创建和运行脚本,但我拥有的唯一条件是在一个剧本中执行所有操作。

4

1 回答 1

3

你可以使用他的剧本:

---
- hosts: ansible-clients
  tasks:
    - name: Fetch source list from clients
      fetch:
        src: /etc/apt/sources.list
        flat: yes
        dest: "/tmp/{{ inventory_hostname }}.sourcelist"
    - name: Merge files
      run_once: yes
      delegate_to: localhost
      shell: "cat /tmp/{{ item }}.sourcelist >> /tmp/allnodes.sourcelist"
      with_items: "{{ groups['ansible-clients'] }}"
  • 第一个任务用于从远程获取所有文件并将它们存储在 /tmp (inventory_hostname) 用于文件名。

  • 第二个任务运行一次,并将所有文件(获取链接到组 ansible-clients 的主机列表)附加到最终文件中

注意:最终文件永远不会被删除,也许你在获取文件之前将其删除(run_once=yes)

于 2016-12-12T13:58:01.707 回答