ansible-lint | Best practices checker | DevOps library
kandi X-RAY | ansible-lint Summary
kandi X-RAY | ansible-lint Summary
Best practices checker for Ansible
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Returns the CLI command line arguments .
- Executes a syntax check on a given lintable .
- Reports failures to the list .
- Merges values from configuration to cli config .
- Check the presence of the ansible CLI module .
- Requests to install a collection .
- Retrieves a list of task handlers for a given child type .
- Installs the galaxy role .
- Normalize task .
- Installs the specified requirement .
ansible-lint Key Features
ansible-lint Examples and Code Snippets
~/projects/localops/test$ ./test-playbook.sh ../user/ansible-lint.yaml
WARNING Overriding detected file kind 'yaml' with 'playbook' for given positional argument: user/ansible-lint.yaml
Static code check found no errors
Testing ubuntu-18.04
PLAY [a
./moleculew test
Additional options:
--ansible VERSION Use the specified version of Ansible
--docker-lib VERSION Use the specified version of the Python Docker
library
--molecule VERSION Use
# See if your code meets all rules.
ansible-lint .
# Test all scenarios.
molecule test
# Test a specific scenario.
molecule test --scenario-name fedora-latest
FROM alpine:3.7
ENV ANSIBLE_VERSION=2.5.4
ENV BUILD_PACKAGES \
bash \
curl \
tar \
nano \
openssh-client \
sshpass \
git \
python \
py-boto \
py-dateutil \
└── default
├── dependency
├── create
├── prepare
└── converge
└── default
├── lint
├── dependency
├── cleanup
├── destroy
├── syntax
├── create
├── prepare
├── conve
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
platforms:
- name: instance
image: centos:7
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfr
Community Discussions
Trending Discussions on ansible-lint
QUESTION
I've been working on creating a YAML re-formatter based on ruamel.yaml (which you can see here). I'm currently using version 0.17.20.
Cleaning up comments and whitespace has been difficult. I want to:
- ensure there is only one space before the
#
for EOL comments - align full line comments with the key or item immediately following
- remove duplicate blank lines so there is at most one blank line
To get closer to achieving that, I have a custom Emitter class where I extend write_comment
to adjust the comments just before writing with super().write_comment(...)
. However, the Emitter does not know about which key or item comes next because comments are generally attached as post comments.
As I've studied the ruamel.yaml
code to figure out how to do this, I found the rtsc
mode (Round Trip Split Comments) which looks fantastic because it separates EOLComment
, BlankLineComment
and FullLineComment
instead of lumping them together.
From what I can tell, the Parser
and Scanner
have been adjusted to capture the comments. So, loading is (mostly?) implemented with this "NEWCMNT" implementation. But Emitter.write_comment expects CommentToken
instead of comment line numbers, so dumping does not work yet.
If I update my Emitter.write_comment method, is that enough to finish dumping? Or what else might be necessary? In one of my tries, I ran into a sys.exit
in ScannedComments.assign_eol()
- what else is needed to finish that?
PS: I wouldn't normally ask how to collaborate on StackOverflow, but this is not a bug report or a feature request, and I'm trying/failing to use a new (undocumented) feature, so I'm filing this here instead of sourceforge.
...ANSWER
Answered 2022-Mar-04 at 20:10rtsc
is work in progress cq work started but unfinished. It's internals will almost certainly change.
Two of the three points you indicate can relatively easy be implemented:
set the column of each comment to 0 ( by recursively going over a loaded data structure similar to here ) if the column is before the position of the end of the value on a line, you'll get one space between the value and the column
at the same time doing the recursion in the previous point. Take each comment value and do something like:
QUESTION
I have an Ansible 2.9.27 and I am trying to add upstream remote for git repositories which I previously cloned with Ansible. Let's assume that already cloned repositories are located in /home/user/Documents/github/
directory and I want to add upstream remote for them (git remote add upstream
for each repo).
The task looks like this:
...ANSWER
Answered 2021-Dec-29 at 18:44Since what you want to achieve is not (yet...) taken in charge by the git
module, this is a very legitimate use of command
.
In such cases, it is possible to silence the specific rule in ansible lint for that specific task.
To go a bit further, your changed_when: false
clause looks a bit like a quick and dirty fix to silence the no-changed-when
rule and can be enhanced in conjunction with a failed_when
clause to detect cases where the remote already exists.
Here is how I would write that task to be idempotent, documented and passing all needed lint rules:
QUESTION
This is more of a styling question. I have this ugly piece of code:
...ANSWER
Answered 2021-Dec-21 at 20:51However, I can't use breaks, e.g.
>
or|
since that will include spaces in the end result, and the code will error.
That is actually only an half true statement.
You can combine it with the whitespace control mechanism of Jinja to remove those unneeded whitespaces.
Basically, adding a dash to the opening or the closing of an expression blocks do trim the extraneous whitespace or carriage return before or after it.
Given:
QUESTION
We are currently using Jenkins, and planning to migrate to Gitlab. We actually have 2 Jenkinsfiles in each repo, 1 is setup as a Multibranch pipeline and runs on all changes. Its is the merge check, that runs all the various linting, tests, building the docker containers etc. The second Jenkinsfile is only ran manually from Jenkins, it takes in all the various input parameters and it deploys the code. Which is mostly coming in from say, the linted Ansible/Terraform and selecting a docker image that would have already been built via the CI side of things.
I know gitlab doesnt support this model, but this project is already MVP'd so re-working how the dev's combined their logic and deployment code together is probably not going to happen.
Is it possibly, in 1 gitlab-ci.yml file to say run these jobs on merge/pushes
and only run this on manual deployment
.
e.g.
...ANSWER
Answered 2021-Oct-14 at 19:21There are multiple options to achieve your goal with minimized configuration effort:
- Working with private jobs and use inheritance or references for easier configuration - doable in one file
- Extract parts into child pipelines for easier usage
I assume you most hate that you have to redefine the rules for your jobs. There are two ways how you can reduce those duplication.
InheritanceCan reduce a lot of duplication, but can also cause problems, with unintended side behaviour.
QUESTION
Got the following odd error with ansible lint and I can't for the life of me figure out what we did wrong, it's probably something incredibly stupid but there you go.
...ANSWER
Answered 2021-Jun-23 at 02:35That's a known issue with ansible-lint
; upgrading to a more recent version such as 5.0.12 will make that go away. If it doesn't for your case, you can either comment on that issue or open a regression at which time you should provide the versions you are using
QUESTION
Is there a better solution than this?
...ANSWER
Answered 2021-May-19 at 09:27You should just be able to use ansible filters to acheive what you're trying to do - in particular, have a look at the regex_replace
filter - see https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-strings-with-regular-expressions
In your example, you can write
QUESTION
To start, I have a basic ansible directory structure for roles.
In the [ansible] directory:
...ANSWER
Answered 2020-Dec-21 at 07:46Q: "gui_utils/tasks/main.yml:4 (couldn't resolve module/action 'tasks'."
A: Remove the keyword tasks from ansible/gui_utils/tasks/main.yml. The task import_tasks is already in the tasks section of the playbook
QUESTION
I have performed ansible lint check on the below yml code, even though there is no trailing spaces, I'm receiving trailing whitespace warning for the indentation that has been given. Can you advice on how that can be overcome
...ANSWER
Answered 2020-Oct-05 at 21:34I'll make wild guesses here (and will remove my answer if I'm totally wrong):
- Your file has CRLF line endings (i.e. windows style line endings)
- You are running
ansible-lint
< 4.0.0
If my guesses are correct, you are suffering from a bug which has been fixed.
Upgrade ansible-lint
and your problem should go away:
QUESTION
I am trying to add a validation step to a gitlab repo holding a single ansible role (with no playbook). The structure of the role looks like :
- .gitlab-ci.yml
- tasks/
- templates/
- files/
- vars/
- handlers/
With the gitlab-ci looking like :
...ANSWER
Answered 2020-Sep-04 at 14:30You should certainly be able to pass multiple YAML files as arguments to ansible-lint
. I have version 4.1.1a0
, and I'm able to use it like this, for example:
QUESTION
I have added a .gitlab-ci.yml
to my private project. One of the steps is to get a role from a private gitlab repo. However this fails with
ANSWER
Answered 2020-Jul-21 at 10:05Running the same command
ansible-galaxy install -r requirements.yml
on my machine runs fine.
That means you have the right public/private key in ~/.ssh/id_rsa
on your machine, and you are executing it locally with your account.
If you copy it in your GitLab step, make sure to check the rights, and possible the passphrase and known_hosts, as in here or in the documentation:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ansible-lint
You can use ansible-lint like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page