当 运行 Ansible 剧本时,在 Ec2.py 中刷新 ElastiCache 时出错
Error refreshing ElastiCache in Ec2.py when running Ansible playbooks
在过去的几天里,当 运行 使用 AWS 云模块的 ansible 剧本或直接 运行 使用 --refresh- 的 ec2.py 文件时,我收到以下错误从我的本地机器缓存命令:
ap:~ ap$ /ansible/inventory/ec2.py --refresh-cache
Traceback (most recent call last):
File "/ansible/inventory/ec2.py", line 1510, in <module>
Ec2Inventory()
File "/ansible/inventory/ec2.py", line 186, in __init__
self.do_api_calls_update_cache()
File "/ansible/inventory/ec2.py", line 492, in do_api_calls_update_cache
self.get_elasticache_replication_groups_by_region(region)
File "/ansible/inventory/ec2.py", line 722, in get_elasticache_replication_groups_by_region
self.add_elasticache_replication_group(replication_group, region)
File "/ansible/inventory/ec2.py", line 1198, in add_elasticache_replication_group
dest = replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address']
TypeError: 'NoneType' object has no attribute '__getitem__'
当 运行 来自 AWS 账户中的 Ec2 实例时,这个问题似乎消失了。
我有最新的 EC2.py 和 EC2.ini 文件,Ansible 版本是 2.2.0.0,安装了 boto3,我确实在 运行 剧本之前设置了有效的 AWS 凭证。
对正在发生的事情有什么想法吗?
在 https://github.com/ansible/ansible/pull/20190
尝试补丁
@@ -1194,13 +1194,14 @@ def add_elasticache_replication_group(self, replication_group, region):
if not self.all_elasticache_replication_groups and replication_group['Status'] != 'available':
return
+ # Skip clusters we cannot address (e.g. private VPC subnet or clustered redis)
+ if replication_group['NodeGroups'][0]['PrimaryEndpoint'] is None or \
+ replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address'] is None:
+ return
+
# Select the best destination address (PrimaryEndpoint)
dest = replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address']
- if not dest:
- # Skip clusters we cannot address (e.g. private VPC subnet)
- return
-
# Add to index
self.index[dest] = [region, replication_group['ReplicationGroupId']]
在过去的几天里,当 运行 使用 AWS 云模块的 ansible 剧本或直接 运行 使用 --refresh- 的 ec2.py 文件时,我收到以下错误从我的本地机器缓存命令:
ap:~ ap$ /ansible/inventory/ec2.py --refresh-cache
Traceback (most recent call last):
File "/ansible/inventory/ec2.py", line 1510, in <module>
Ec2Inventory()
File "/ansible/inventory/ec2.py", line 186, in __init__
self.do_api_calls_update_cache()
File "/ansible/inventory/ec2.py", line 492, in do_api_calls_update_cache
self.get_elasticache_replication_groups_by_region(region)
File "/ansible/inventory/ec2.py", line 722, in get_elasticache_replication_groups_by_region
self.add_elasticache_replication_group(replication_group, region)
File "/ansible/inventory/ec2.py", line 1198, in add_elasticache_replication_group
dest = replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address']
TypeError: 'NoneType' object has no attribute '__getitem__'
当 运行 来自 AWS 账户中的 Ec2 实例时,这个问题似乎消失了。
我有最新的 EC2.py 和 EC2.ini 文件,Ansible 版本是 2.2.0.0,安装了 boto3,我确实在 运行 剧本之前设置了有效的 AWS 凭证。
对正在发生的事情有什么想法吗?
在 https://github.com/ansible/ansible/pull/20190
尝试补丁
@@ -1194,13 +1194,14 @@ def add_elasticache_replication_group(self, replication_group, region):
if not self.all_elasticache_replication_groups and replication_group['Status'] != 'available':
return
+ # Skip clusters we cannot address (e.g. private VPC subnet or clustered redis)
+ if replication_group['NodeGroups'][0]['PrimaryEndpoint'] is None or \
+ replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address'] is None:
+ return
+
# Select the best destination address (PrimaryEndpoint)
dest = replication_group['NodeGroups'][0]['PrimaryEndpoint']['Address']
- if not dest:
- # Skip clusters we cannot address (e.g. private VPC subnet)
- return
-
# Add to index
self.index[dest] = [region, replication_group['ReplicationGroupId']]