LINT
ANSIBLE LINT
Section titled “ANSIBLE LINT”Installer Lint
Section titled “Installer Lint”Install avec pip
$ pip3 install ansible-lintSyntaxe
$ ansible-lint --helpusage: 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 :
$ ansible-lint -v -TLimiter à certaines règles
$ ansible-lint -t idempotency playbook.ymlExclure certaines règles
$ ansible-lint -x formatting,metadata playbook.ymlIgnorer les warnings
$ ansible-lint -w experimental playbook.ymlUtilisation
$ ansible-lint playbook.yml -vvDEBUG Loading rules from /home/sadmin/.Vpy36/lib/python3.6/site-packages/ansiblelint/rulesINFO Executing syntax check on playbook.yml (0.70s)DEBUG Examining playbook.yml of type playbookWARNING Listing 1 violation(s) that are fatalunnamed-task: All tasks should be namedplaybook.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-lintwarn_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.Exemple
Section titled “Exemple”Exécuter la commande lint sur cet exemple et ensuite réparer
$ vi playbook.yml---- 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$ ansible-lint playbook.yml