renamed files; added playbook for rhel8
This commit is contained in:
parent
21815d7ee1
commit
d4532be2c2
128
test-lint-rhel8.yml
Normal file
128
test-lint-rhel8.yml
Normal file
@ -0,0 +1,128 @@
|
||||
- name: Test Ansible Lint Formatting via VirtualEnv
|
||||
hosts: all
|
||||
become: true
|
||||
gather_facts: true
|
||||
|
||||
|
||||
vars:
|
||||
ansible_lint_vers : "6.13.1"
|
||||
ansible_lint_venv : /tmp/ansible-lint-venv
|
||||
git_repo_to_lint : https://gitea.thezengarden.net/chris/ansible-lint-poc.git
|
||||
lint_work_dir : /tmp/lint_repository
|
||||
|
||||
|
||||
tasks:
|
||||
- name: Ensure virtualenv command is present
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- virtualenv
|
||||
state: present
|
||||
|
||||
|
||||
- name: Create VirtualEnv and Install ansible-lint
|
||||
ansible.builtin.pip:
|
||||
name: "ansible-lint=={{ ansible_lint_vers }}"
|
||||
virtualenv: "{{ ansible_lint_venv }}"
|
||||
virtualenv_python: python3.9
|
||||
|
||||
|
||||
- name: Ansible Lint Debug Information
|
||||
block:
|
||||
- name: Test Ansible Lint - Version
|
||||
ansible.builtin.command: "{{ ansible_lint_venv }}/bin/ansible-lint --nocolor --version"
|
||||
register: r_lint_version
|
||||
changed_when: false
|
||||
|
||||
|
||||
- name: Test Ansible Lint - Help
|
||||
ansible.builtin.command: "{{ ansible_lint_venv }}/bin/ansible-lint --nocolor --help"
|
||||
register: r_lint_help
|
||||
changed_when: false
|
||||
|
||||
|
||||
- name: Show ansible-lint infos
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "'ansible-lint --version': {{ r_lint_version['stdout'] }}"
|
||||
- "'ansible-lint --help': {{ r_lint_help['stdout'] }}"
|
||||
verbosity: 1
|
||||
|
||||
|
||||
- name: Create destination for cloned repositories
|
||||
ansible.builtin.file:
|
||||
path: "{{ lint_work_dir }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
|
||||
- name: Clone target repository into
|
||||
ansible.builtin.git:
|
||||
repo: "{{ git_repo_to_lint }}"
|
||||
dest: "{{ lint_work_dir }}"
|
||||
version: main
|
||||
|
||||
|
||||
- name: Test Ansible Lint - Playbooks/Roles
|
||||
ansible.builtin.command:
|
||||
cmd: "{{ ansible_lint_venv }}/bin/ansible-lint --nocolor --format json"
|
||||
chdir: "{{ lint_work_dir }}"
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
register: r_lint_output
|
||||
|
||||
|
||||
- name: Debug r_lint_output
|
||||
ansible.builtin.debug:
|
||||
verbosity: 1
|
||||
var: r_lint_output['stdout']
|
||||
|
||||
|
||||
- name: Capture ansible-lint warnings and errors
|
||||
ansible.builtin.set_fact:
|
||||
r_lint_warnings: "{{ r_lint_output['stdout'] | from_json | selectattr('level', 'equalto', 'warning') }}"
|
||||
r_lint_failures: "{{ r_lint_output['stdout'] | from_json | selectattr('level', 'equalto', 'error') }}"
|
||||
|
||||
|
||||
- name: Debug r_lint_warnings
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "File: {{ item['location']['path'] }}"
|
||||
- "Line Number: {{ item['location']['lines']['begin'] }}"
|
||||
- "Level: {{ item['level'] }}"
|
||||
- "Severity: {{ item['severity'] }}"
|
||||
- "Description: {{ item['description'] }}"
|
||||
loop: "{{ r_lint_warnings }}"
|
||||
loop_control:
|
||||
label: "{{ item['location']['path'] }}"
|
||||
|
||||
|
||||
- name: Debug r_lint_failures
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "File: {{ item['location']['path'] }}"
|
||||
- "Line Number: {{ item['location']['lines']['begin'] }}"
|
||||
- "Level: {{ item['level'] }}"
|
||||
- "Severity: {{ item['severity'] }}"
|
||||
- "Description: {{ item['description'] }}"
|
||||
loop: "{{ r_lint_failures }}"
|
||||
loop_control:
|
||||
label: "{{ item['location']['path'] }}"
|
||||
|
||||
|
||||
- name: Cleanup repository destination
|
||||
ansible.builtin.file:
|
||||
path: "{{ lint_work_dir }}"
|
||||
state: absent
|
||||
|
||||
|
||||
- name: Cleanup Virtual Environment
|
||||
ansible.builtin.file:
|
||||
path: "{{ ansible_lint_venv }}"
|
||||
state: absent
|
||||
|
||||
|
||||
- name: Cleanup installed packages
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- virtualenv
|
||||
state: absent
|
Loading…
x
Reference in New Issue
Block a user