alibaba / footmark

Apache License 2.0
14 stars 17 forks source link

UnboundLocalError: local variable 'filters' referenced before assignment #30

Open atodorov opened 5 years ago

atodorov commented 5 years ago
$ ansible localhost -c local -m ali_instance_facts -a 'alicloud_region=us-east-1 availability_zone=us-east-1-a' -vvv
ansible 2.8.0b1.post0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/atodorov/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/atodorov/.virtualenvs/alibaba/lib/python2.7/site-packages/ansible
  executable location = /home/atodorov/.virtualenvs/alibaba/bin/ansible
  python version = 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass it's verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
META: ran handlers
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: atodorov
<127.0.0.1> EXEC /bin/sh -c 'echo ~atodorov && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160 `" && echo ansible-tmp-1556112722.38-56948253796160="` echo /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160 `" ) && sleep 0'
Using module file /home/atodorov/.virtualenvs/alibaba/lib/python2.7/site-packages/ansible/modules/cloud/alicloud/ali_instance_facts.py
<127.0.0.1> PUT /home/atodorov/.ansible/tmp/ansible-local-269724TbdZ6/tmpiCoiNO TO /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/ /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/home/atodorov/.virtualenvs/alibaba/bin/python /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py", line 114, in <module>
    _ansiballz_main()
  File "/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py", line 106, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py", line 49, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/tmp/ansible_ali_instance_facts_payload_qZeeM9/__main__.py", line 396, in <module>
  File "/tmp/ansible_ali_instance_facts_payload_qZeeM9/__main__.py", line 388, in main
  File "/home/atodorov/.virtualenvs/alibaba/lib/python2.7/site-packages/footmark/ecs/connection.py", line 267, in get_all_instances
    for inst in self.get_list_new(self.build_request_params(filters), ['Instances', Instance]):
UnboundLocalError: local variable 'filters' referenced before assignment

localhost | FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py\", line 114, in <module>\n    _ansiballz_main()\n  File \"/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/atodorov/.ansible/tmp/ansible-tmp-1556112722.38-56948253796160/AnsiballZ_ali_instance_facts.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_ali_instance_facts_payload_qZeeM9/__main__.py\", line 396, in <module>\n  File \"/tmp/ansible_ali_instance_facts_payload_qZeeM9/__main__.py\", line 388, in main\n  File \"/home/atodorov/.virtualenvs/alibaba/lib/python2.7/site-packages/footmark/ecs/connection.py\", line 267, in get_all_instances\n    for inst in self.get_list_new(self.build_request_params(filters), ['Instances', Instance]):\nUnboundLocalError: local variable 'filters' referenced before assignment\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

This is with 1.11.0, here's my entire pip freeze b/c I've installed ansible 2.8 from GitHub:

aliyun-python-sdk-core==2.9.5
aliyun-python-sdk-ecs==4.11.0
aliyun-python-sdk-ess==2.3.0
aliyun-python-sdk-kms==2.6.0
aliyun-python-sdk-ossadmin==0.0.2
aliyun-python-sdk-rds==2.3.3
aliyun-python-sdk-slb==3.2.7
aliyun-python-sdk-vpc==3.0.2
ansible==2.8.0b1.post0
asn1crypto==0.24.0
certifi==2019.3.9
cffi==1.12.3
chardet==3.0.4
crcmod==1.7
cryptography==2.6.1
enum34==1.1.6
footmark==1.11.0
idna==2.8
importlib==1.0.4
ipaddress==1.0.22
Jinja2==2.10.1
MarkupSafe==1.1.1
oss2==2.6.1
pycparser==2.19
pycryptodome==3.8.1
PyYAML==5.1
requests==2.21.0
six==1.12.0
urllib3==1.24.2
xiaozhu36 commented 5 years ago

HI @atodorov This issue seems like using a incompatible ansible package. At present, the PR has not been merged by ansible official. If you want to using the latest footmark to run ansible alibaba cloud module, you should install ansible_alicloud

atodorov commented 5 years ago

At present, the PR has not been merged by ansible official.

you should try making this piece of code not fail then. I will try ansible_alicloud.

xuanyunhui commented 4 years ago

@xiaozhu36 python3上运行失败,是不是这个版本还不支持python3?

lixue323 commented 4 years ago

@xuanyunhui footmark从1.13.0版本开始仅支持python3.6。推荐使用目前最新版本1.15.0。

xuanyunhui commented 4 years ago

sh-4.4# ansible --version
ansible 2.8.5 config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.6/site-packages/ansible executable location = /usr/bin/ansible python version = 3.6.8 (default, Oct 11 2019, 15:04:54) [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)]

sh-4.4# pip3 list aliyun-python-sdk-alidns (2.0.14) aliyun-python-sdk-core (2.13.13) aliyun-python-sdk-core-v3 (2.13.11) aliyun-python-sdk-ecs (4.11.0) aliyun-python-sdk-ess (2.3.0) aliyun-python-sdk-rds (2.4.4) aliyun-python-sdk-slb (3.2.7) aliyun-python-sdk-sts (3.0.1) aliyun-python-sdk-vpc (3.0.7) ansible (2.8.5) asn1crypto (0.24.0) Babel (2.5.1) bcrypt (3.1.6) cffi (1.11.5) cryptography (2.3) dbus-python (1.2.4) decorator (4.2.1) ethtool (0.14) footmark (1.15.0) gpg (1.10.0) idna (2.5) iniparse (0.4) Jinja2 (2.10.1) jmespath (0.9.4) MarkupSafe (0.23) paramiko (2.4.3) pip (9.0.3) ply (3.9) pyasn1 (0.3.7) pycparser (2.14) pycryptodome (3.9.4) pygobject (3.28.3) pyinotify (0.9.6) PyNaCl (1.3.0) python-dateutil (2.6.1) python-dmidecode (3.12.2) pytz (2017.2) PyYAML (3.12) rpm (4.14.2) setuptools (39.2.0) six (1.11.0) subscription-manager (1.25.17) syspurpose (1.25.17)

The full traceback is: Traceback (most recent call last): File "/root/.ansible/tmp/ansible-tmp-1579594959.5246859-181561173959184/AnsiballZ_ali_instance.py", line 114, in _ansiballz_main() File "/root/.ansible/tmp/ansible-tmp-1579594959.5246859-181561173959184/AnsiballZ_ali_instance.py", line 106, in _ansiballz_main invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS) File "/root/.ansible/tmp/ansible-tmp-1579594959.5246859-181561173959184/AnsiballZ_ali_instance.py", line 49, in invoke_module imp.load_module('main', mod, module, MOD_DESC) File "/usr/lib64/python3.6/imp.py", line 235, in load_module return load_source(name, filename, file) File "/usr/lib64/python3.6/imp.py", line 170, in load_source module = _exec(spec, sys.modules[name]) File "", line 618, in _exec File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/tmp/ansible_ali_instance_payload_skmna0u3/main.py", line 779, in File "/tmp/ansible_ali_instance_payload_skmna0u3/main.py", line 655, in main File "/usr/local/lib/python3.6/site-packages/footmark/ecs/connection.py", line 285, in get_all_instances for inst in self.get_list_new(self.build_request_params(filters), ['Instances', Instance]): UnboundLocalError: local variable 'filters' referenced before assignment

@lixue323 已经是1.15.0版本的,感觉是python3兼容性的问题

lixue323 commented 4 years ago

@xuanyunhui pip install virtualenv 安装虚拟环境 virtualenv env3 --python=python3 创建3的虚拟环境env3 source env3/bin/activate 激活虚拟环境 pip install ansible_alicloud 在虚拟环境中安装ansible_alicloud 在虚拟环境中,麻烦再运行一下文件。 应该是python2与python3共存的问题。

xuanyunhui commented 4 years ago

@lixue323 我新起一个干净的CentOS8系统,按照你的步骤执行,之后运行测试的playbook问提依旧。再附上我的测试playbook

- name: Create a new ECS
  hosts: localhost
  connection: local
  tasks:
  - name: Create an ECS instance
    ali_instance:
      alicloud_region: cn-beijing
      image_id: centos_8_0_x64_20G_alibase_20191225.vhd
      instance_type: ecs.c6.large
      instance_name: jenkins-master
      host_name: jenkins-dna-1.pub.bj
      key_name: '***'
      vswitch_id: vsw-*********
      security_groups: sg-**********
      count: '1'
      allocate_public_ip: false
      instance_tags:
        role: jenkins
    register: ecs
  - name: output information of the vm
    debug:
      msg: "The created vm is {{ ecs }}."
xuanyunhui commented 4 years ago

@lixue323 我测试下来最终看来这个问题确实是包冲突引起的,我的环境里只有一个版本的python,可以排除python版本的问题,但是env环境和机器环境的模块包有区别。我再排查一下,有进度再来反馈

lixue323 commented 4 years ago

@xuanyunhui 启动虚拟环境,pip install ansible_alicloud --no-cache-dir 在虚拟环境中在试一下。

xuanyunhui commented 4 years ago

@lixue323 我找到最终的原因了,ansible里面已经集成的alicloud的模块,这个模块不兼容footmark,默认调用的是ansible自己的模块,我把调用改成优先调用pip install的alicloud模块就能正常工作了。 ansible-alicloud这个最新的版本会PR到ansible吗?

lixue323 commented 4 years ago

@xuanyunhui pip install ansible_alicloud 执行这个命令之后,会自动安装footmark以及ansible, 并且会替换最新的alicloud到ansible中,你的问题是出现在先手动安装了ansible。ansible中alicloud不是最新版本。感谢你的反馈,对于我们非常有帮助。