首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ansible V2 -> "skip_reason":“条件检查失败”with_items

ansible V2 -> "skip_reason":“条件检查失败”with_items
EN

Stack Overflow用户
提问于 2016-08-19 18:16:46
回答 1查看 3.4K关注 0票数 0

我在执行以下操作时遇到一些错误:

group_vars:

代码语言:javascript
复制
tomcat_servers:
- name: tomcat_1
  shutdown_port: 8005
  connector_port: 8080
  ajp_port: 8009
- name: tomcat_2
  shutdown_port: 8105
  connector_port: 8180
  ajp_port: 8109

主代码:

代码语言:javascript
复制
  - name: "Check if tomcat is already installed"
    stat: path={{ tomcat_server_dir }}/{{ item.name }}/RELEASE-NOTES
    register: status
    with_items: "{{ tomcat_servers }}"

  - debug: var=status

  - name: "Copy tomcat into folder if it is not installed"
    command: /bin/tar -zxvf /tmp/{{ tomcat_catalina_base }} -C {{ tomcat_server_dir }}/{{ item.name }} --strip 2
when: not status.results[0].stat.exists
with_items:
  - "{{ tomcat_servers }}"
  - "{{ status.results }}"

调试结果:

代码语言:javascript
复制
    ok: [VM1] => {
        "status": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "changed": false,
                "invocation": {
                    "module_args": {
                        "checksum_algorithm": "sha1",
                        "follow": false,
                        "get_checksum": true,
                        "get_md5": true,
                        "mime": false,
                        "path": "/opt/tomcat_3/RELEASE-NOTES"
                    },
                    "module_name": "stat"
                },
                "item": {
                    "ajp_port": 8009,
                    "connector_port": 8080,
                    "name": "tomcat_1",
                    "shutdown_port": 8005
                },
                "stat": {
                    "exists": false
                },
                {
                    "_ansible_item_result": true,
                    "_ansible_no_log": false,
                    "changed": false,
                    "invocation": {
                        "module_args": {
                            "checksum_algorithm": "sha1",
                            "follow": false,
                            "get_checksum": true,
                            "get_md5": true,
                            "mime": false,
                            "path": "/opt/tomcat_3/RELEASE-NOTES"
                        },
                        "module_name": "stat"
                    },
                    "item": {
                        "ajp_port": 8109,
                        "connector_port": 8180,
                        "name": "tomcat_2",
                        "shutdown_port": 8105
                    },
                    "stat": {
                    "exists": false
                }
        }
    ]
    }
}

现在,不幸的是,我似乎得到了错误

代码语言:javascript
复制
"skip_reason": "Conditional check failed", "skipped": true

我已经问了很多次“你用谷歌搜索过了吗”,但似乎找不到解决方案。谷歌ansible check if file exists with_items,你可能会看到同样的结果。

有谁知道怎么让它工作吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-19 19:04:50

正确的第二个循环:

代码语言:javascript
复制
---
- hosts: localhost
  vars:
    results:
      - item:
          ajp_port: 8009
          connector_port: 8080
          name: tomcat_1
          shutdown_port: 8005
        stat:
          exists: false
      - item:
          ajp_port: 8109
          connector_port: 8180
          name: tomcat_2
          shutdown_port: 8105
        stat:
          exists: false
      - item:
          name: tomcat_exist
        stat:
          exists: true

  tasks:
    - debug:
        msg: "name: {{ item.item.name }}, exists: {{ item.stat.exists }}"
      when: not item.stat.exists
      with_items: "{{ results }}"

因此,在您的设置中,您需要遍历status.results并引用item.item.nameitem.stat.exists

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39036503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档