alibaba.alicloud
alibaba.alicloud copied to clipboard
Not able to add backend server to existing SLB
Description:
We are trying to add the new ECS instance to the existing SLB with Ansible.
- The same playbook for the Hong Kong region is working as well.
- The same playbook for the Tokyo region is not working.
- As per documentation the environment variables are not respecting by ali_slb_server module:
https://www.diewufeiyang.com/ansible/en/modules/ali_slb_server_module.html
ALICLOUD_REGION or ALICLOUD_REGION_ID can be typically be used to specify the ALICLOUD region, when required, but this can also be configured in the footmark config file
The issue:
The specified LoadBalancerId does not exist.
The output:
raise exception\naliyunsdkcore.acs_exception.exceptions.ServerException: HTTP Status: 404 Error:InvalidLoadBalancerId.NotFound The specified LoadBalancerId does not exist. RequestID: FF49FF87-09FA-41EE-8444-154C53E6E619\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1
The code:
playbooks/slb_update.yml
- name: Add ECS instances to SLB
hosts: localhost
vars:
alicloud_access_key: '{{ ALICLOUD_ACCESS_KEY }}'
alicloud_secret_key: '{{ ALICLOUD_SECRET_KEY }}'
alicloud_region: 'ap-northeast-1'
tasks:
- name: SLB update
ali_slb_server:
alicloud_access_key: '{{ alicloud_access_key }}'
alicloud_secret_key: '{{ alicloud_secret_key }}'
load_balancer_id: lb-foo
backend_servers:
- server_id: i-bar
weight: 100
Similar issue: https://github.com/alibaba/alibaba.alicloud/issues/143
The solution:
I found the issue in the Python script: https://github.com/alibaba/alibaba.alicloud/blob/aa6b0eaab7150abe294bca4e29e9239f0c843831/lib/ansible/modules/cloud/alicloud/ali_slb_server.py
# handling region parameter which is required by common utils file to login but not required by this module
module.params['alicloud_region'] = 'cn-hangzhou
The HK region is hardcoded.
Suggestion:
The region should be specified by the user and the HK should be used by default.
{"changed": false, "msg": "Unsupported parameters for (ali_slb_server) module: alicloud_region Supported parameters include:
alicloud_access_key, alicloud_assume_role, alicloud_assume_role_arn, alicloud_assume_role_session_expiration, alicloud_assume_role_session_name, alicloud_secret_key, alicloud_security_token, backend_servers, ecs_role_name, load_balancer_id, profile, shared_credentials_file, state"}
alicloud_region should be possible to define in ali_slb_server section in Ansible playbook or the region environment should be respected.
Temporary solution:
Please go to the Ansible modules directory.
ansible-playbook --version
ansible-playbook 2.9.13
config file = None
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible-playbook
cd /usr/local/lib/python3.6/site-packages/ansible/modules/cloud/alicloud
find the ali_slb_server.py file and go to the 386 line to change the region variable.
Regions IDs: https://www.alibabacloud.com/help/doc-detail/40654.ht