【问题标题】:Ansible - Hide values loop account creationAnsible - 隐藏值循环帐户创建
【发布时间】:2022-09-29 04:06:12
【问题描述】:

我尝试在 ansible 上创建带有循环的本地帐户。

密码在 group_vars 中

- name: \"Add users\"
  user:
    name: \"{{item.name}}\"
    uid: \"{{item.uid}}\"
    password: \"{{ item.name | string | password_hash(\'sha512\') }}\"
    group: toto
    update_password: always
    comment: toto
    shell: /bin/bash
    password_expire_max: 365
  loop:
    - { uid: 12000, name: \'toto\', password: \"{{ toto  | string | password_hash(\'sha512\') }}\" } 

当我启动我的剧本时,密码在循环中以 SHA 打印

ok: [192.168.113.199] => (item={u\'password\': u\' password in sha \', u\'uid\': 12000, u\'name\': u\'toto\'})

有人知道如何隐藏密码吗? 提前谢谢

  • 将此no_log: true 添加到任务中

标签: loops ansible


【解决方案1】:

当我启动我的剧本时,密码在循环中以 SHA 打印

您可以查看Adding controls to loopsLimiting loop output with label 并额外使用

  loop_control:
    label: "{{ item.name }}"

这会将控制台输出限制为仅用户名键和值。 Extended loop variables 也可以提供优势。

【讨论】:

    【解决方案2】:

    当您处理敏感数据时,您始终可以为您的任务使用“no_log: true”选项。这样循环的项目将不会向控制台显示输出。

    我看到 U888D 建议使用 Limiting loop output with label,但是,在同一页面上它是这样说的:

    这是为了使控制台输出更具可读性,而不是保护 敏感数据。如果循环中有敏感数据,设置 no_log: yes on 防止泄露的任务。

    有关 no_log 的更多信息,您可以在此处查看:Protecting sensitive data with no_log

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-17
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多