Ansible - 基于 dict 的循环,stat 不起作用

杰弗里·庞森

我目前正在创建使用我的 ansible-playbook 自动获取 Letsencrypt 证书的可能性。

我想检查 /etc/letsencrypt/domain.tld 目录是否存在,如果不存在,我需要获取证书。

---
- name: LETSENCRYPT | Checking for existing certificates
  stat:
    path: /etc/letsencrypt/live/{{ item.value.server_name }}
  register: le_cert_exists
  with_dict: "{{ sites }}"
  when: item.value.letsencrypt | default(false) | bool

- name: DEBUG | Output result of le cert exists
  debug:
    var: le_cert_exists

- name: LETSENCRYPT | Output sites that need a new certificate
  debug:
    msg: Obtain certificate here
    var: item.item
  with_items: le_cert_exists.results
  when: item.stat.exists is defined and not item.stat.exists

到目前为止,它正在工作,除了最后一个功能。最后一个任务一直被跳过或失败并出现以下错误:

fatal: [-]: FAILED! => {"msg": "The conditional check 'item.stat.exists is defined and not item.stat.exists' failed. The error was: error while evaluating conditional (item.stat.exists is defined and not item.stat.exists): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'stat'\n\nThe error appears to have been in '/path/to/main.yml': line 13, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: LETSENCRYPT | Output sites that need a new certificate\n  ^ here\n"}

有没有人有一个如何轻松完成此操作的示例?

当目录不存在时,我只需要执行一个命令。

康斯坦丁·苏沃洛夫

with_items: le_cert_exists.results是错误的,
with_items: "{{ le_cert_exists.results }}"是正确的。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

C ++基于范围的for循环遍历valarray rvalue不起作用

来自分类Dev

基于范围的循环中的常量引用不起作用

来自分类Dev

Ansible sudo不起作用

来自分类Dev

Ansible 代码不起作用

来自分类Dev

Ansible 中的 dict 循环内循环

来自分类Dev

Ansible-with_fileglob循环-变得_user不起作用-在源计算机上运行操作

来自分类Dev

For循环不起作用

来自分类Dev

For 循环不起作用

来自分类Dev

for 循环不起作用

来自分类Dev

循环不起作用

来自分类Dev

python dict和函数不起作用

来自分类Dev

基于点击的移动不起作用

来自分类Dev

基于键的字典过滤不起作用

来自分类Dev

基于文本的游戏代码不起作用?

来自分类Dev

Ansible wait_for似乎不起作用

来自分类Dev

Ansible 临时命令后台不起作用

来自分类Dev

ANSIBLE 不起作用 - 语法检查

来自分类Dev

为什么在std :: map上基于范围的for循环中的const std :: pair <K,V>&不起作用?

来自分类Dev

Bash脚本从中派生n个变量,直到基于n个迭代的循环变量不起作用为止

来自分类Dev

循环范围不起作用

来自分类Dev

对于循环不起作用

来自分类Dev

While循环不起作用

来自分类Dev

Swift for循环不起作用

来自分类Dev

双for循环不起作用

来自分类Dev

+ =在For循环中不起作用

来自分类Dev

对于循环不起作用

来自分类Dev

While循环不起作用

来自分类Dev

Javascript:for 循环不起作用

来自分类Dev

JS for 循环不起作用