跳到内容

avoid-implicit

此规则识别危险的隐式行为的使用,这些行为通常也未被文档化。

此规则将产生以下类型的错误消息

  • avoid-implicit[copy-content] 不是字符串,因为 copy 模块也接受这些,但没有记录它们。

有问题的代码

---
- name: Example playbook
  hosts: localhost
  tasks:
    - name: Write file content
      ansible.builtin.copy:
        content: { "foo": "bar" } # <-- should use explicit jinja template
        dest: /tmp/foo.txt

正确的代码

---
- name: Example playbook
  hosts: localhost
  tasks:
    - name: Write file content
      vars:
        content: { "foo": "bar" }
      ansible.builtin.copy:
        content: "{{ content | to_json }}" # explicit better than implicit!
        dest: /tmp/foo.txt