Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use official Ansible container for ansible-lint #100

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ The following is an example of a `tox.ini` from the kernel_settings role:
lsr_enable = true
commands_pre = bash -c '{toxinidir}/tests/install_tuned_for_testing.sh || {toxinidir}/tests/kernel_settings/install_tuned_for_testing.sh'

[lsr_ansible-lint]
configfile = {toxinidir}/.ansible-lint

[lsr_yamllint]
configfile = {toxinidir}/.yamllint.yml
configbasename = .yamllint.yml
Expand Down Expand Up @@ -250,9 +247,8 @@ Then doing `tox -e flake8` would use your flake8.conf.

### Using setenv and environment variables

These environment variables can be set in your local tox.ini `testenv` section,
or in your CI configuration e.g. `.github/workflows/tox.yml`. Some of the
environment variables we used in the old scripts are carried over:
These environment variables can be set in your local tox.ini `testenv` section.
Some of the environment variables we used in the old scripts are carried over:
* `RUN_PYTEST_SETUP_MODULE_UTILS` - if set to an arbitrary non-empty value, the
environment will be configured so that tests of the `module_utils/` code will be
run correctly
Expand All @@ -265,22 +261,6 @@ environment variables we used in the old scripts are carried over:
`--ignore=some,errs`
* `RUN_BLACK_EXTRA_ARGS` - any extra command line arguments to provide e.g.
`--ignore=some,errs`
* `LSR_EXTRA_PACKAGES` - set in `.github/workflows/tox.yml` - list of extra
packages to install in the CI environment (typically an Ubuntu variant)
* `LSR_ANSIBLES` - set in `.github/workflows/tox.yml` - ansible versions to test
molecule against in the form that is used with pip e.g. use
`LSR_ANSIBLES='ansible==2.8.* ansible==2.9.*'` to use ansible 2.8 and ansible
2.9. Only ansible 2.8 and higher are supported. tox-lsr 2.0 uses molecule v3,
which does not work with ansible 2.7 or earlier.
* `LSR_MSCENARIOS` - set in `.github/workflows/tox.yml` - molecule scenarios to
test
* `LSR_MOLECULE_DRIVER` - default `docker` - The molecule driver to use. If you
want to use `podman`, use `LSR_MOLECULE_DRIVER=podman`
* `LSR_MOLECULE_DRIVER_VERSION` - default empty - use this if you want to
override the version of the molecule driver pypi package - otherwise, the
correct version will be auto-detected. E.g.
`LSR_MOLECULE_DRIVER=podman LSR_MOLECULE_DRIVER_VERSION='<4.4'` will evaluate
to something like `pip install podman<4.4`
* `LSR_PUBLISH_COVERAGE` - If the variable is unset or empty (the default), no
coverage is published. Other valid values for the variable are:
* `strict` - the reporting is performed in strict mode, so situations like
Expand Down Expand Up @@ -321,16 +301,31 @@ environment variables:
* `RUN_YAMLLINT_CONFIG_FILE` - path to config file to use instead of the default
* `LSR_ANSIBLE_TEST_DOCKER` - if set to `true`, `ansible-test` will be run with
`--docker`
* `LSR_ANSIBLE_LINT_DEP` - this is the dep to pass when doing the pip install of
ansible for ansible-lint. The default is `ansible-core==2.12.*`.
* `LSR_ANSIBLE_LINT_VER` - this is the version of ansible-lint to install for
the ansible-lint testenv. The default is `5.2.0`.
* `LSR_ANSIBLE_TEST_DEP` - this is the dep to pass when doing the pip install of
ansible for ansible-test. The default is `ansible-core==2.12.*`.
* `LSR_PYLINT_ANSIBLE_DEP` - this is the dep to pass when doing the pip install of
ansible for pylint. The default is `ansible-core==2.12.*`.
* `LSR_RUN_TEST_DIR` - this is the directory to use to override `changedir`, for
those tests that need it, primarily the tests run "recursively" via `-e collection`
* `LSR_CONTAINER_RUNTIME` - default `podman` - set to `docker` if you must

These environment variables are deprecated and will be removed soon:
* `LSR_EXTRA_PACKAGES` - set in `.github/workflows/tox.yml` - list of extra
packages to install in the CI environment (typically an Ubuntu variant)
* `LSR_ANSIBLES` - set in `.github/workflows/tox.yml` - ansible versions to test
molecule against in the form that is used with pip e.g. use
`LSR_ANSIBLES='ansible==2.8.* ansible==2.9.*'` to use ansible 2.8 and ansible
2.9. Only ansible 2.8 and higher are supported. tox-lsr 2.0 uses molecule v3,
which does not work with ansible 2.7 or earlier.
* `LSR_MSCENARIOS` - set in `.github/workflows/tox.yml` - molecule scenarios to
test
* `LSR_MOLECULE_DRIVER` - default `docker` - The molecule driver to use. If you
want to use `podman`, use `LSR_MOLECULE_DRIVER=podman`
* `LSR_MOLECULE_DRIVER_VERSION` - default empty - use this if you want to
override the version of the molecule driver pypi package - otherwise, the
correct version will be auto-detected. E.g.
`LSR_MOLECULE_DRIVER=podman LSR_MOLECULE_DRIVER_VERSION='<4.4'` will evaluate
to something like `pip install podman<4.4`

These environment variables have been removed:
* `RUN_PYLINT_INCLUDE` - use `RUN_PYLINT_EXTRA_ARGS`
Expand Down
3 changes: 0 additions & 3 deletions src/tox_lsr/config_files/ansible-lint.yml

This file was deleted.

18 changes: 8 additions & 10 deletions src/tox_lsr/config_files/tox-default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,21 @@ commands =
bash {lsr_scriptdir}/runshellcheck.sh
{[lsr_config]commands_post}

[lsr_ansible-lint]
configfile = {lsr_configdir}/ansible-lint.yml

[testenv:ansible-lint]
changedir = {toxinidir}
deps =
{env:LSR_ANSIBLE_LINT_DEP:ansible-core==2.14.*}
ansible-lint=={env:LSR_ANSIBLE_LINT_VER:5.*}
whitelist_externals =
podman
bash
commands_pre =
bash {lsr_scriptdir}/ansible-lint-helper.sh pre
commands =
bash {lsr_scriptdir}/setup_module_utils.sh
{[lsr_config]commands_pre}
ansible-lint -v --exclude=tests/roles --exclude=.github \
--exclude=.yamllint.yml \
-c {[lsr_ansible-lint]configfile} \
{env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs}
{env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to add the description to README.md. But it's a very minor issue...

By default, it will use podman to run the container. You can set LSR_CONTAINER_RUNTIME to use a different runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated
also deprecated several old env. vars.

-v {toxinidir}:/workdir --workdir /workdir \
--entrypoint /usr/local/bin/ansible-lint \
quay.io/ansible/creator-ee:v0.9.5 \
{env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs}
{[lsr_config]commands_post}
commands_post =
bash {lsr_scriptdir}/ansible-lint-helper.sh post
Expand Down
14 changes: 6 additions & 8 deletions tests/fixtures/test_tox_merge_ini/result.ini
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,17 @@ commands = bash {lsr_scriptdir}/setup_module_utils.sh
bash {lsr_scriptdir}/runshellcheck.sh
{[lsr_config]commands_post}

[lsr_ansible-lint]
configfile = {lsr_configdir}/ansible-lint.yml

[testenv:ansible-lint]
changedir = {toxinidir}
deps = {env:LSR_ANSIBLE_LINT_DEP:ansible-core==2.14.*}
ansible-lint=={env:LSR_ANSIBLE_LINT_VER:5.*}
whitelist_externals = podman
bash
commands_pre = bash {lsr_scriptdir}/ansible-lint-helper.sh pre
commands = bash {lsr_scriptdir}/setup_module_utils.sh
{[lsr_config]commands_pre}
ansible-lint -v --exclude=tests/roles --exclude=.github \
--exclude=.yamllint.yml \
-c {[lsr_ansible-lint]configfile} \
{env:LSR_CONTAINER_RUNTIME:podman} run --rm --privileged \
-v {toxinidir}:/workdir --workdir /workdir \
--entrypoint /usr/local/bin/ansible-lint \
quay.io/ansible/creator-ee:v0.9.5 \
{env:RUN_ANSIBLE_LINT_EXTRA_ARGS:} {posargs}
{[lsr_config]commands_post}
commands_post = bash {lsr_scriptdir}/ansible-lint-helper.sh post
Expand Down