【问题标题】:Need to use Azure Keyvault Secret value as a variable in Ansible需要在 Ansible 中使用 Azure Keyvault Secret 值作为变量
【发布时间】:2022-02-18 18:09:33
【问题描述】:

我想在 ansible 中创建一个用户,并且在创建用户时我想传递我将从 ansible Key Vault 获得的密码。请让我知道该怎么做。我已经关注了微软文档链接https://docs.microsoft.com/en-us/azure/developer/ansible/key-vault-configure-secrets?tabs=ansible

  user: 
    name: username  
    uid: UID
    group: grpname
    shell: /bin/bash
    comment: "test user"
    password: < **Secret Key value from ansible key vault** >```

请帮助我从 azure key vault 获取密钥值。

【问题讨论】:

  • 我们能知道到目前为止您已经尝试过什么吗?

标签: azure ansible azure-keyvault ansible-2.x


【解决方案1】:

你可以这样做:

tasks:
- name: connect AzPowerShell to Azure
  shell: |
    az login --service-principal -u "{{ servicePrincipalId }}" -p "{{ servicePrincipalPassword }}" --tenant "{{ tenantId }}"
  args:
    executable: /usr/bin/bash
- name: Run a pwsh command
  shell: az keyvault secret show --name "{{ vaultSecretName }}" --vault-name "{{ vaultName }}" --query value -o tsv
  args:
    executable: /usr/bin/bash
  register: result
- debug:
    msg: "{{ result.stdout }}"

这个例子来自https://github.com/CloudSkills/using-ansible-with-azure/blob/master/5-lookup-azure-key-vault-secrets-with-ansible/lookup-azure-key-vault-secrets-with-ansible.md

我建议您通读整个 git repo - 这是对 ansible 和 azure 工作流程的很好解释。

【讨论】:

    猜你喜欢
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多