python - Ansible:“NetworkManagementClient”对象没有属性“private_endpoints”
问题描述
我尝试使用Ansible为存储帐户部署私有端点。我正在使用azure.azcollection.azure_rm_privateendpoint。我的剧本代码如下:
- name: Create PE
hosts: localhost
connection: local
tasks:
- name: create_pe
azure.azcollection.azure_rm_privateendpoint:
name: testprivateendpoint
resource_group: MYRG
private_link_service_connections:
- name: pe-satest
group_ids: blob
private_link_service_id: /subscriptions/xxxxxxxxx/resourceGroups/MYRG/providers/Microsoft.Storage/storageAccounts/mysa
subnet:
id: /subscriptions/xxxxxxx/resourceGroups/MYRG-VNET/providers/Microsoft.Network/virtualNetworks/MYVNET/subnets/mySubnet
启动 ansible-playbook 命令后,出现以下错误:
TASK [create_pe] ****************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error creating or updating private endpoint testprivateendpoint - 'NetworkManagementClient' object has no attribute 'private_endpoints'"}
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
- 可以从具有相同属性的 Azure 门户手动创建专用终结点。
- 子网的专用终结点网络策略已禁用。
- 我最初的 Ansible 版本是2.9。出现错误后,我已将其更新为Ansible 4.6,但仍然出现相同的错误。
- 我的操作系统是 RHEL 8.4。
- 蟒蛇 3.6
关于这个错误的来源有什么想法吗?
解决方案
这个错误"msg": "Error creating or updating private endpoint testprivateendpoint - 'NetworkManagementClient' object has no attribute 'private_endpoints'"
是由于NetworkManagementClient
无法获取导致的private_endpoints
。
您可以尝试添加以下代码来解决它:
创建azure_rm_privateendpoint.py
并将其包含在您的剧本中,例如main.yml
. 您可以参考How to run a python script from an ansible playbook、Running Python script via ansible和Running custom python script using ansible script module
def get_item(self):
self.log('Get properties for {0}'.format(self.name))
item = None
results = []
try:
item = self.network_client.private_endpoints.get(self.resource_group, self.name)
except Exception:
self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
format_item = self.privateendpoints_to_dict(item)
if format_item and self.has_tags(format_item['tags'], self.tags):
results = [format_item]
return results
def list_resource_group(self):
self.log('List items for resource group')
try:
response = self.network_client.private_endpoints.list(self.resource_group)
except CloudError as exc:
self.fail("Failed to list for resource group {0} - {1}".format(self.resource_group, str(exc)))
results = []
for item in response:
format_item = self.privateendpoints_to_dict(item)
if self.has_tags(format_item['tags'], self.tags):
results.append(format_item)
return results
def list_items(self):
self.log('List all for items')
try:
response = self.network_client.private_endpoints.list_by_subscription()
except CloudError as exc:
self.fail("Failed to list all items - {0}".format(str(exc)))
results = []
for item in response:
format_item = self.privateendpoints_to_dict(item)
if self.has_tags(format_item['tags'], self.tags):
results.append(format_item)
return results
可以参考azure_rm_privateendpoint_info.py、azure_rm_privateendpoint.py和Azure rm privateendpoint
如果仍然遇到同样的错误,可以在 GitHub 上打开一个问题:ansible-collections/azure
推荐阅读
- powershell - Powershell Select-String -ExactMatch?
- html - Django Crispy Forms 不显示某个字段的边框
- flutter - 找不到正确的提供者
高于此消费者 小部件 - mule-studio - Unable to resolve reference to Class loaded via External library
- visual-studio - Visual Studio 中的 CMake 设置问题
- ruby-on-rails - 浏览器中的 Rails API 路径给出此错误 NoMethodError undefined method `[]' for nil:NilClass
- sql - Power Bi SQL - 不支持语义查询
- amazon-web-services - 如何使用Lamda函数在RDS中使用CDK创建表?
- functional-programming - 如何正确使用 Result.bind
- java - 根据JAVA列表内对象的属性将新对象添加到对象列表中