使用Ansible获取Azure密钥保管库机密-如何告诉Ansible脚本中的Azure_preview_modules



我正在尝试获得一个Ansible剧本,以便能够读取Azure密钥库中的秘密,如下页所示https://learn.microsoft.com/en-us/azure/developer/ansible/key-vault-configure-secrets?tabs=ansible#get-来自钥匙库的秘密。这看起来很简单。我的行动手册如下:

---
- name: key vault testing
hosts: localhost
connection: local
roles: 
-  { role: azure.azure_preview_modules }
vars:
tenant_id: xxxxxxxxxxxxxx
vault_name: xxxxxxxxx
secret_name: xxxxxxxxxxxxxxx
client_id: xxxxxxxxxxxxxxxx
client_secret: xxxxxxxxxxxxxxx
tasks:
- name: Get Key Vault by name
azure_rm_keyvault_info:
resource_group: xxxxxxxxxx
name: "{{ vault_name }}"
register: keyvault
- name: Set key vault URI fact
set_fact: keyvaulturi="{{ keyvault['keyvaults'][0]['vault_uri'] }}"
- name: Set key vault secret fact
set_fact: secretValue={{ lookup('azure_keyvault_secret',secret_name,vault_url=keyvaulturi, client_id=client_id, secret=client_secret, tenant_id=tenant_id) }}
- name: Output key vault secret
debug:
msg: "{{ secretValue }}"

当我运行这个时,我得到以下输出/错误:

PLAY [key vault testing] ********************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [azure.azure_preview_modules : Install Azure Python SDK required by modules.] **********************************************************************************************************************************************************
ok: [localhost]
TASK [azure.azure_preview_modules : debug] **************************************************************************************************************************************************************************************************
ok: [localhost] => {
"msg": [
"Your Ansible version is lower than 2.5.0",
"You may need to perform additional steps to install this roles:",
"  sudo pip install -r /home/administrator/.ansible/roles/azure.azure_preview_modules/files/requirements-azure.txt",
"or",
"  pip install --user -r /home/administrator/.ansible/roles/azure.azure_preview_modules/files/requirements-azure.txt",
"depending on your ansible setup."
]
}
TASK [Get Key Vault by name] ****************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: AnsibleModule.__init__() got an unexpected keyword argument 'check_invalid_arguments'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):n  File "/home/administrator/.ansible/tmp/ansible-tmp-1660655181.949111-2808-175135597436300/AnsiballZ_azure_rm_keyvault_info.py", line 107, in <module>n    _ansiballz_main()n  File "/home/administrator/.ansible/tmp/ansible-tmp-1660655181.949111-2808-175135597436300/AnsiballZ_azure_rm_keyvault_info.py", line 99, in _ansiballz_mainn    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)n  File "/home/administrator/.ansible/tmp/ansible-tmp-1660655181.949111-2808-175135597436300/AnsiballZ_azure_rm_keyvault_info.py", line 47, in invoke_modulen    runpy.run_module(mod_name='ansible.modules.azure_rm_keyvault_info', init_globals=dict(_module_fqn='ansible.modules.azure_rm_keyvault_info', _modlib_path=modlib_path),n  File "/usr/lib/python3.10/runpy.py", line 209, in run_modulen    return _run_module_code(code, init_globals, run_name, mod_spec)n  File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_coden    _run_code(code, mod_globals, init_globals,n  File "/usr/lib/python3.10/runpy.py", line 86, in _run_coden    exec(code, run_globals)n  File "/tmp/ansible_azure_rm_keyvault_info_payload_7xtlk5_l/ansible_azure_rm_keyvault_info_payload.zip/ansible/modules/azure_rm_keyvault_info.py", line 323, in <module>n  File "/tmp/ansible_azure_rm_keyvault_info_payload_7xtlk5_l/ansible_azure_rm_keyvault_info_payload.zip/ansible/modules/azure_rm_keyvault_info.py", line 319, in mainn  File "/tmp/ansible_azure_rm_keyvault_info_payload_7xtlk5_l/ansible_azure_rm_keyvault_info_payload.zip/ansible/modules/azure_rm_keyvault_info.py", line 227, in __init__n  File "/tmp/ansible_azure_rm_keyvault_info_payload_7xtlk5_l/ansible_azure_rm_keyvault_info_payload.zip/ansible/module_utils/azure_rm_common.py", line 288, in __init__nTypeError: AnsibleModule.__init__() got an unexpected keyword argument 'check_invalid_arguments'n", "module_stdout": "", "msg": "MODULE FAILUREnSee stdout/stderr for the exact error", "rc": 1}
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

我使用的是安装在Hyper-V中的ubuntu 22.04,并遵循了此处的Ansible安装说明https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html.我能很好地运行其他Ansible剧本。我已经安装了带有ansible-galaxy install azure.azure_preview_modules的azure_preview_modules。我想我的错误可能是在这个部分:

"Your Ansible version is lower than 2.5.0"

如果我运行ansible --version,我会得到以下输出:

ansible [core 2.13.3]
config file = None
configured module search path = ['/home/administrator/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/administrator/.local/lib/python3.10/site-packages/ansible
ansible collection location = /home/administrator/.ansible/collections:/usr/share/ansible/collections
executable location = /home/administrator/.local/bin/ansible
python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]
jinja version = 3.1.2
libyaml = True

这告诉我,我的Ansible版本不低于2.5.0,这就是为什么我认为这是我应该开始寻找的地方。有人有什么想法我可以试试吗?我正要把我所有的头发都拔出来!!!谢谢Andrew

TASK[azure.azure_preview_modules:debug]*ok:[localhost]=>{"msg":["您的Ansible版本低于2.5.0";,"您可能需要执行其他步骤来安装此角色:";,任务执行期间发生异常。查看完整的

由于您的ansible-galaxy install azure.azure_preview_modules在战术手册中为2.5.0而发生上述错误

通常的战术手册:

多个集合可能具有相同名称的模块(例如,user(,因此在Ansible 2.10及更高版本中,请确保在您的剧本中使用完全限定的集合名称,以便选择正确的模块。

剧本可能无法处理低于ansible版本2.10的参数

可能需要解决的条件:

  • 卸载Ansible

    sudo apt remove ansible

  • 使用pip 安装Ansible

    pip3 install ansible

  • 安装系统范围的apt

    sudo apt install ansible

参考:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html

相关内容

  • 没有找到相关文章

最新更新