Skip to content

LINT

Install avec pip

Terminal window
$ pip3 install ansible-lint

Syntaxe

Terminal window
$ ansible-lint --help
Terminal window
usage: ansible-lint [-h] [-L] [-f {rich,plain,rst,codeclimate,quiet,pep8}]
[-q] [-p] [--parseable-severity] [--progressive]
[--project-dir PROJECT_DIR] [-r RULESDIR] [-R]
[--show-relpath] [-t TAGS] [-T] [-v] [-x SKIP_LIST]
[-w WARN_LIST] [--enable-list ENABLE_LIST] [--nocolor]
[--force-color] [--exclude EXCLUDE_PATHS] [-c CONFIG_FILE]
[--offline] [--version]
[lintables [lintables ...]]

Pour afficher toutes les règles utilisées par défaut il suffit de taper la commande suivante :

Terminal window
$ ansible-lint -v -T

Limiter à certaines règles

Terminal window
$ ansible-lint -t idempotency playbook.yml

Exclure certaines règles

Terminal window
$ ansible-lint -x formatting,metadata playbook.yml

Ignorer les warnings

Terminal window
$ ansible-lint -w experimental playbook.yml

Utilisation

Terminal window
$ ansible-lint playbook.yml -vv
Terminal window
DEBUG Loading rules from /home/sadmin/.Vpy36/lib/python3.6/site-packages/ansiblelint/rules
INFO Executing syntax check on playbook.yml (0.70s)
DEBUG Examining playbook.yml of type playbook
WARNING Listing 1 violation(s) that are fatal
unnamed-task: All tasks should be named
playbook.yml:67 Task/Handler: firewalld port=80/tcp permanent=True immediate=True zone=public state=enabled
You can skip specific rules or tags by adding them to your configuration file:
# .ansible-lint
warn_list: # or 'skip_list' to silence them completely
- unnamed-task # All tasks should be named
Finished with 1 failure(s), 0 warning(s) on 1 files.

Exécuter la commande lint sur cet exemple et ensuite réparer

Terminal window
$ vi playbook.yml
Terminal window
---
- hosts: all
gather_facts: no
tasks:
- name: this would typically fire deprecated-command-syntax
command: chmod 644 fic
- name: this would typically fire command-instead-of-module
command: git pull https://github.com/ansible/awx.git
- name: Run apt-get update
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
force_apt_get: true
ignore_errors: true
Terminal window
$ ansible-lint playbook.yml