amazon-web-servicesansibleaws-secrets-manager

How do you set key/value secret in AWS secrets manager using Ansible?


The following code does not set the key/value pair for secrets. It only creates a string. But I want to create key/value and the documentation does not even mention it....

- 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


Solution

  • IF this matches anything like the Secrets Manager CLI then to set key values pairs you should expect to create a key value pair like the below:

    - 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