no-log-password¶
此规则确保 playbook 在使用循环时不会将密码写入日志。始终设置 no_log: true
属性来保护敏感数据。
虽然大多数 Ansible 模块会屏蔽敏感数据,但在循环中使用密钥可能会导致这些密钥被记录到日志中。显式添加 no_log: true
可以防止意外暴露密钥。
有问题的代码¶
---
- name: Example playbook
hosts: localhost
tasks:
- name: Log user passwords
ansible.builtin.user:
name: john_doe
comment: John Doe
uid: 1040
group: admin
password: "{{ item }}"
with_items:
- wow
no_log: false # <- Sets the no_log attribute to false.
正确的代码¶
---
- name: Example playbook
hosts: localhost
tasks:
- name: Do not log user passwords
ansible.builtin.user:
name: john_doe
comment: John Doe
uid: 1040
group: admin
password: "{{ item }}"
with_items:
- wow
no_log: true # <- Sets the no_log attribute to a non-false value.
注意
此规则可以使用 --fix
选项自动修复。