【发布时间】:2022-11-07 23:42:12
【问题描述】:
我有一个自定义模块,它位于我的 Ansible 角色的 library/ 目录中。我可以从我的剧本中调用该模块,并且代码可以正确执行,但前提是它期望的值在模块代码本身中被硬编码。如何将值从剧本传递给模块?
我尝试了以下方法:
- name: Create repo and use specific KMS key
ecr_kms:
repositoryName: "new-ecr-repo"
encryptionConfiguration.kmsKey: 'my-kms-key-id"
和
- name: Create repo and use specific KMS key
ecr_kms:
repositoryName: "{{ repo_name }}"
encryptionConfiguration.kmsKey: "{{ kms_key_id }}"
我希望它可以工作,但也没有,而且我收到以下错误:
botocore.exceptions.ParamValidationError:参数验证失败:
参数 repositoryName 的长度无效,值:0,有效的最小长度:2
参数encryptionConfiguration.kmsKey的长度无效,值:0,有效最小长度:1The service module I'm trying to use
自定义模块的代码:
#!/usr/bin/python from urllib import response import boto3 from jinja2 import Template from ansible.module_utils.basic import AnsibleModule def create_repo(): client = boto3.client('ecr') response = client.create_repository( #registryId='', repositoryName='', imageTagMutability='IMMUTABLE', imageScanningConfiguration={ 'scanOnPush': True }, encryptionConfiguration={ 'encryptionType': 'KMS', 'kmsKey': "" } ) def main(): create_repo() if __name__ in '__main__': main()
【问题讨论】:
标签: ansible amazon-ecr amazon-kms ansible-role ansible-module