alibaba.alicloud
alibaba.alicloud copied to clipboard
filters on tags does not work for alicloud_ecs.py with python 3.8
Filter on tags does not work anymore with ansible on python 3.8. It works on python 3.6.
Here the filers part from alicloud.yml
filters:
tags:
Name: myhostname
# ansible-inventory --version
ansible-inventory [core 2.12.4.post0]
config file = /runner/ansible.cfg
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
jinja version = 2.10.3
libyaml = True
# pip list | grep -E "footmark|ali"
aliyun-python-sdk-alidns 2.6.32
aliyun-python-sdk-core 2.13.36
aliyun-python-sdk-ecs 4.24.13
aliyun-python-sdk-ess 2.3.3
aliyun-python-sdk-kms 2.15.0
aliyun-python-sdk-market 2.0.24
aliyun-python-sdk-oos 1.5.0
aliyun-python-sdk-ram 3.2.0
aliyun-python-sdk-rds 2.6.1
aliyun-python-sdk-ros 3.2.0
aliyun-python-sdk-slb 3.3.13
aliyun-python-sdk-sts 3.1.0
aliyun-python-sdk-vpc 3.0.16
ansible-alicloud 1.19.0
ansible-alicloud-module-utils 1.5.0
footmark 1.21.0
The ansible-inventory return all ecs instances.
ansible-inventory -i alicloud.yml --list
Filtering on instance ids works.
HI @mick1627 I am sorry for late reply. Can you share me the error when running alicloud_ecs.py with python 3.8?
@amolari Can you share us the error when running alicloud_ecs.py with python 3.8?
@zopcorn There is no error, but the filtering is ignored.
@amolari Do you want to get some instances by filters dynamically? If so, you can refer to https://docs.ansible.com/ansible/latest/user_guide/intro_dynamic_inventory.html#other-inventory-scripts .
@xiaozhu36 : we're using AWX/tower, so filter partly dynamically through limits. However, we need some pre-filtering (for safety) at the inventory level too. That was working perfectly before using Pythong 3.8.
@amolari would you please try to use aliyun-python-sdk-ecs with version 2.1.3 ? Since we do not have your ansible playbook, we are not able to test it.
filters on tags is now working with pip module aliyun-python-sdk-ecs version 4.24.22
But now I have an other issue setting setting hostname variables to a specific tag does not work anymore.
Here my alicloud.yml file
plugin: alicloud_ecs
alicloud_region: cn-shanghai
keyed_groups:
# add hosts to instance_type groups
- prefix: instance_type
key: instance_type
# add hosts to instance_name groups
- key: instance_name
prefix: name
- key: availability_zone
prefix: ''
separator: ''
- key: "availability_zone | regex_replace('^(.*)-[^-]+$', '\\1')"
prefix: ''
separator: ''
- key: tags
prefix: tag
parent_group: tags
cache: false
cache_plugin: jsonfile
cache_timeout: 7200
cache_connection: /tmp/alicloud_inventory
cache_prefix: alicloud_ecs
# Add hosts to group based on Jinja2 conditionals
groups:
# add hosts to the group Spinnaker if instance_name starts with 'k8sSpinnaker'
# Spinnaker: instance_name.startswith('k8sSpinnaker')
# Create vars from jinja2 expressions
compose:
# set the ansible_host variable to connect with the public ip address without changing the hostnames
ansible_host: private_ip_address
#If true make invalid entries a fatal error, otherwise skip and continue
#Since it is possible to use facts in the expressions they might not always be available and we ignore those errors by default.
strict: false
filters:
tags:
Name: stfeagt04
hostnames:
- tags: fqdn
@zopcorn you can test the inventory plugins with the command ansible-inventory -i alicloud.yml --list no needs to run playbook.
@mick1627 OK, let me have a check.
@xiaozhu36 any news please?
Hi @amolari @mick1627 I am sorry for late reply. This issue has been fixed the by #309 and you can build a new collection to have a try.
In addition, the hostnames
in inventory file should be as following:
hostnames:
- tag:fqdn