首页 > 解决方案 > 如何使用 Ansible 在 AWS 机密管理器中设置键/值机密?

问题描述

以下代码未设置密钥的键/值对。它只创建一个字符串。但我想创建键/值,文档甚至没有提到它......

- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: Add string to AWS Secrets Manager
      aws_secret:
        name: 'testvar'
        state: present
        secret_type: 'string'
        secret: "i love devops"
      register: secret_facts
    - debug:
        var: secret_facts

标签: amazon-web-servicesansibleaws-secrets-manager

解决方案


如果这与Secrets Manager CLI之类的任何内容匹配,那么要设置键值对,您应该期望创建如下所示的键值对:

- hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: Add string to AWS Secrets Manager
      aws_secret:
        name: 'testvar'
        state: present
        secret_type: 'string'
        secret: "{\"username\":\"bob\",\"password\":\"abc123xyz456\"}"
      register: secret_facts
    - debug:
        var: secret_facts

推荐阅读