ansible-lint is not working complaining about ansible module missing:
birin@librem13:~$ ansible-lint Traceback (most recent call last): File "/usr/bin/ansible-lint", line 11, in <module> load_entry_point('ansible-lint==3.4.20', 'console_scripts', 'ansible-lint')() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 487, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2728, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2346, in load return self.resolve() File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2352, in resolve module = __import__(self.module_name, fromlist=['__name__'], level=0) File "/usr/lib/python2.7/dist-packages/ansiblelint/__init__.py", line 28, in <module> import ansiblelint.utils File "/usr/lib/python2.7/dist-packages/ansiblelint/utils.py", line 26, in <module> from ansible import constants ImportError: No module named ansible
Looks like the new ansible 2.7.6+dfsg-1 is using python3 while ansible-lint uses python2. Therefore when 'ansible-lint' looks for ansible libraries under Python2 directories it does not find them:
birin@librem13:~$ apt-cache show ansible Package: ansible Version: 2.7.6+dfsg-1 Installed-Size: 33734 Maintainer: Harlan Lieberman-Berg <hlieberman@debian.org> Architecture: all Depends: python3-cryptography, python3-jinja2, python3-paramiko, python3-pkg-resources, python3-yaml, python3:any, python3-crypto, python3-httplib2, python3-netaddr Recommends: python3-jmespath, python3-kerberos, python3-libcloud, python3-selinux, python3-winrm (>= 0.1.1), python3-xmltodict Suggests: cowsay, sshpass Description-en: Configuration management, deployment, and task execution system Ansible is a radically simple model-driven configuration management, multi-node deployment, and remote task execution system. Ansible works over SSH and does not require any software or daemons to be installed on remote nodes. Extension modules can be written in any language and are transferred to managed machines automatically. Description-md5: db2b21b0d2286fccc4401d5982361488 Homepage: https://www.ansible.com Section: admin Priority: optional Filename: pool/main/a/ansible/ansible_2.7.6+dfsg-1_all.deb Size: 3955540 SHA256: 2758ffe1587dbcf18b31934b8046709c51ec3b1e567449e137059c599fdd230d birin@librem13:~$ apt-cache show ansible-lint Package: ansible-lint Version: 3.4.20+git.20180203-1 Installed-Size: 143 Maintainer: Gregory Colpart <reg@debian.org> Architecture: all Depends: ansible, python-six, python-yaml, python:any (<< 2.8), python:any (>= 2.7.5-5~) Description-en: lint tool for Ansible playbooks Ansible playbooks express configuration, deployment and orchestration in YAML format. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process. . ansible-lint checks Ansible playbooks for practices and behaviour that could potentially be improved. Description-md5: a381932960794814b41d4276fb69f7a5 Homepage: https://github.com/willthames/ansible-lint Section: misc Priority: optional Filename: pool/main/a/ansible-lint/ansible-lint_3.4.20+git.20180203-1_all.deb Size: 24764 SHA256: 5acfdab3a258599da98df64b44f25ba6ec0fca2c4b7453ae86314392e6b13acb
A workaround is to use ansible-lint in a virtualenv:
birin@librem13:~$ virtualenv --python=python3 ansible_python3 Already using interpreter /usr/bin/python3 Using base prefix '/usr' New python executable in /home/birin/ansible_python3/bin/python3 Also creating executable in /home/birin/ansible_python3/bin/python Installing setuptools, pkg_resources, pip, wheel...done. birin@librem13:~$ source ansible_python3/bin/activate (ansible_python3) birin@librem13:~$ pip install ansible-lint Collecting ansible-lint Using cached https://files.pythonhosted.org/packages/7d/ac/908e2bb33564640a321fd7d88c465073e643de24c0f941c90be7a05ec68c/ansible_lint-4.1.0-py2.py3-none-any.whl Collecting pyyaml (from ansible-lint) Collecting ansible (from ansible-lint) Collecting six (from ansible-lint) Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl Collecting ruamel.yaml (from ansible-lint) Using cached https://files.pythonhosted.org/packages/d5/37/54020dea78a2df39ff1dcb0efa5f78de58e865ac913828305f70f06662fe/ruamel.yaml-0.15.87-cp37-cp37m-manylinux1_x86_64.whl Collecting cryptography (from ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/98/71/e632e222f34632e0527dd41799f7847305e701f38f512d81bdf96009bca4/cryptography-2.5-cp34-abi3-manylinux1_x86_64.whl Requirement already satisfied: setuptools in ./ansible_python3/lib/python3.7/site-packages (from ansible->ansible-lint) (40.8.0) Collecting jinja2 (from ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl Collecting paramiko (from ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba20114fa947d7ba6eb68a2e452d89b920e62227/paramiko-2.4.2-py2.py3-none-any.whl Collecting cffi!=1.11.3,>=1.8 (from cryptography->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/51/7b/d1014289d0578c3522b2798b9cb87c65e5b36798bd3ae68a75fa1fe09e78/cffi-1.11.5-cp37-cp37m-manylinux1_x86_64.whl Collecting asn1crypto>=0.21.0 (from cryptography->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl Collecting MarkupSafe>=0.23 (from jinja2->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/e4/c4/adcc2d6f2ac2146cc04e076f14f1006c1de8e1e747fa067668b6573000b8/MarkupSafe-1.1.0-cp37-cp37m-manylinux1_x86_64.whl Collecting bcrypt>=3.1.3 (from paramiko->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/d0/79/79a4d167a31cc206117d9b396926615fa9c1fdbd52017bcced80937ac501/bcrypt-3.1.6-cp34-abi3-manylinux1_x86_64.whl Collecting pynacl>=1.0.1 (from paramiko->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/27/15/2cd0a203f318c2240b42cd9dd13c931ddd61067809fee3479f44f086103e/PyNaCl-1.3.0-cp34-abi3-manylinux1_x86_64.whl Collecting pyasn1>=0.1.7 (from paramiko->ansible->ansible-lint) Using cached https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography->ansible->ansible-lint) Installing collected packages: pyyaml, six, pycparser, cffi, asn1crypto, cryptography, MarkupSafe, jinja2, bcrypt, pynacl, pyasn1, paramiko, ansible, ruamel.yaml, ansible-lint Successfully installed MarkupSafe-1.1.0 ansible-2.7.7 ansible-lint-4.1.0 asn1crypto-0.24.0 bcrypt-3.1.6 cffi-1.11.5 cryptography-2.5 jinja2-2.10 paramiko-2.4.2 pyasn1-0.4.5 pycparser-2.19 pynacl-1.3.0 pyyaml-3.13 ruamel.yaml-0.15.87 six-1.12.0 (ansible_python3) birin@librem13:~$ ansible-lint Usage: ansible-lint [options] playbook.yml [playbook2 ...] Options: --version show program's version number and exit -h, --help show this help message and exit -L list all the rules -q quieter, although not silent output -p parseable output in the format of pep8 --parseable-severity parseable output including severity of rule -r RULESDIR specify one or more rules directories using one or more -r arguments. Any -r flags override the default rules in /home/birin/ansible_python3/lib/python3.7/site- packages/ansiblelint/rules, unless -R is also used. -R Use default rules in /home/birin/ansible_python3/lib/python3.7/site- packages/ansiblelint/rules in addition to any extra rules directories specified with -r. There is no need to specify this if no -r flags are used -t TAGS only check rules whose id/tags match these values -T list all the tags -v Increase verbosity level -x SKIP_LIST only check rules whose id/tags do not match these values --nocolor disable colored output --force-color Try force colored output (relying on ansible's code) --exclude=EXCLUDE_PATHS path to directories or files to skip. This option is repeatable. -c C Specify configuration file to use. Defaults to ".ansible-lint"
Please notice that you can use Python2 or Python3 for your virtualenv... I just happened to choose Python3 for the ticket example.
Cheers,
Birin