小编Mar*_*n P的帖子

Ansible - 如何从"FIND"模块注册输出并在其他模块中使用

我需要在未知目录位置找到文件并删除它们.试图使用"查找"模块,注册其输出,并将其传递给"文件".

即使我看到注册路径,我也不能在以后使用它:

< TASK [print find_result] >
ok: [1.2.3.4] => {
    "find_result": {
        "changed": false, 
        "examined": 3119, 
        "files": [
            {
                "atime": 1483973253.7295375, 
           ...
                "mode": "0600", 
                "mtime": 1483973253.7295375, 
                "nlink": 1, 
                "path": "/tmp/delme", 
Run Code Online (Sandbox Code Playgroud)

我的剧本是:

- hosts: "{{ target }}"
  become: no
  vars:
    find_what: "delme*"
    find_where: "/tmp"

  tasks:
  - name: finding files
    find:
      paths:            "{{ find_where }}"
      patterns:         "{{ find_what }}"
      recurse:          "yes"
      file_type:        "file"
    register: find_result

# \/ for debugging
  - name: print find_result
    debug: var=find_result

  - name: remove files
    file:
        path= …
Run Code Online (Sandbox Code Playgroud)

ansible

7
推荐指数
1
解决办法
2万
查看次数

ansible - 组合三个字典列表

在我的剧本中,我从多个来源收集有关应用程序的事实,最终得到 3 个(或更多)列表,每个列表都有一个 dict。

有没有办法将这种结构组合成一个字典列表。如果没有,关于我需要如何更改数据结构的任何建议?

我的代码试图组合2 个字典列表(即使在最终用例中也会有 3 个或更多)。

所有war_ *名单应该有相同数量的字典,用钥匙“APP_NAME”,只是随意选择我们作为war_time迭代器-和APP_NAME是普通其中全部

- hosts: localhost
  vars:
    war_status:
    - app_name: app1-SNAPSHOT
      app_status: running
    - app_name: app2
      app_status: stopped
    - app_name: app3-jsf
      app_status: unknown

    war_time:
    - app_name: app1-SNAPSHOT
      app_time: '2017-07-07 06:38:30'
    - app_name: app2
      app_time: '2018-07-19 09:16:57'
    - app_name: app3-jsf
      app_time: '2019-07-21 06:00:57'

    war_proxy_status:
    - app_name: app1-SNAPSHOT
      app_where_found: inst1
    - app_name: app2
      app_where_found: inst2
    - app_name: app3-jsf
      app_where_found: inst3

  tasks:

  - set_fact:
      war_combined: []

  - name: combine1 war_status and …
Run Code Online (Sandbox Code Playgroud)

dictionary ansible

1
推荐指数
1
解决办法
3976
查看次数

标签 统计

ansible ×2

dictionary ×1