【发布时间】:2019-07-26 10:10:01
【问题描述】:
我需要知道为什么这段代码如果失败和/或如何实现它,因为我无法做到
我运行了这段 ansible,它使用每个主机的寄存器列表来检查获取 path 值的证书的状态。
但似乎我没有以正确的方式访问字典。
register_variable得到的数据结构
ok: [node01] => {
"service_certificate_found": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"examined": 12,
"failed": false,
"files": [
{
"atime": 1552906907.033556,
"ctime": 1552906907.033556,
"dev": 66305,
"gid": 999,
"inode": 302256,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1552906906.6615531,
"nlink": 1,
"path": "/etc/keys/collectorCA.crt",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 2061,
"uid": 1012,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
{
"atime": 1552906902.7015238,
"ctime": 1552906902.7015238,
"dev": 66305,
"gid": 999,
"inode": 302254,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0644",
"mtime": 1552906902.3415213,
"nlink": 1,
"path": "/etc/keys/InterCA.crt",
"rgrp": true,
"roth": true,
"rusr": true,
"size": 1554,
"uid": 1012,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
}
]
}
]
}
}
Ansible sn-p
- name: Check certificate is valid and on the right place
block:
- name: First find the certificates
find:
paths: "{{ item }}"
recurse: yes
register: service_certificate_found
with_items:
- "{{ service_certificate_paths }}"
- name: Now check everyone of them
openssl_certificate:
path: "{{ item.item.path }}"
provider: assertonly
has_expired: false
with_items: "{{ service_certificate_found.results }}"
Ansible 错误
TASK [pb.servicetest : Now check everyone of them] ********************************************************************************************************************************************************
Friday 26 July 2019 11:58:56 +0200 (0:00:00.055) 0:00:03.856 ***********
fatal: [node1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'path'\n\nThe error appears to be in '/Users/me/repos/ansible-servicetest/tasks/main.yml': line 42, column 15, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - debug: var=service_certificate_found\n ^ here\n\nThere appears to be both 'k=v' shorthand syntax and YAML in this task. Only one syntax may be used.\n"}
想法?
【问题讨论】:
-
嗨。 1)您注册的 var 示例不完整(尝试加载时出现语法错误) 2)您粘贴的错误与您的 sn-p 中的任何行无关:它与有语法问题的调试任务有关(不支持k=v + yaml 的混合)。请花时间在帮助部分查看"How to create a minimal reproducible example"。