0%

Ansible-part8: Ansible lint

Ansible lint: Ansible Lint is a commandline tool for linting playbooks. Use it to detect behaviors and practices that could potentially be improved.

Install

At first I try to Use pip install ansible-int, it failed.
then I try the apt install.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/set-fact module$ sudo apt install ansible-lint
[sudo] password for anna:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
golang-1.10-go golang-1.10-race-detector-runtime golang-1.10-src golang-race-detector-runtime golang-src ieee-data pkg-config python-certifi python-chardet python-jmespath python-kerberos python-libcloud python-lockfile python-netaddr
python-openssl python-requests python-selinux python-simplejson python-urllib3 python-xmltodict
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
ansible-lint
0 upgraded, 1 newly installed, 0 to remove and 34 not upgraded.
Need to get 24.8 kB of archives.
After this operation, 146 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 ansible-lint all 3.4.20+git.20180203-1 [24.8 kB]
Fetched 24.8 kB in 0s (76.1 kB/s)
Selecting previously unselected package ansible-lint.
(Reading database ... 240199 files and directories currently installed.)
Preparing to unpack .../ansible-lint_3.4.20+git.20180203-1_all.deb ...
Unpacking ansible-lint (3.4.20+git.20180203-1) ...
Setting up ansible-lint (3.4.20+git.20180203-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/set-fact module$ ansible-lint --version
ansible-lint 3.4.20

It shows the lint version is 3.4.20

use lint to test yml file

1
2
3
4
5
6
7
8
9
10


anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/packaging_modules/inventory$ ansible-lint site.yml
[ANSIBLE0002] Trailing whitespace
site.yml:10
name:

[ANSIBLE0010] Package installs should not use latest
site.yml:16
Task/Handler: test apt module

then I go to line 10 to add ‘test package module’ after name, and save playbook.
after run ansible-lint

1
2
3
4
anna@ansible-controller:~/Desktop/ansible-code/inventory/modules/packaging_modules/inventory$ ansible-lint site.yml
[ANSIBLE0010] Package installs should not use latest
site.yml:16
Task/Handler: test apt module

It only shows the second code which needs improved.

after I commented out the state: latest, the output of ansible-lint site.yml shows nothing, which means nothing needs improve in this site.yml file.