Closed officel closed 2 years ago
I was able to get this working: (this doesn't cover the action part)
$ ansible-galaxy collection install community.general
---
- name: timezone
hosts: all
gather_facts: true
vars:
tz: Asia/Tokyo
tasks:
- name: "Set the timezone. {{ tz }}"
community.general.timezone:
name: "{{ tz }}"
failed_when: false
@ssbarnea @cidrblock thank you! I could complete.
my repo(ommit)
$ tree
.
|-- ansible
| |-- .ansible-lint
| |-- requirements.yml
| `-- roles
my wf
steps:
- uses: actions/checkout@master
- name: copy .ansible-lint
shell: bash
run: |
cp ansible/.ansible-lint .
cp ansible/requirements.yml .
- name: Lint Ansible Playbook
uses: ansible/ansible-lint-action@v6
# uses: ./.github/actions/ansible-lint
with:
args: ansible
wooops
$ cat ansible/requirements.yml
---
collections:
- community.general
$ cat ansible/.ansible-lint
# see https://ansible-lint.readthedocs.io/en/latest/configuring/
# List of additional kind:pattern to be added at the top of the default
# match list, first match determines the file kind.
kinds:
- playbook: "**/playbook*/*.{yml,yaml}"
# - galaxy: "**/folder/galaxy.yml"
# - tasks: "**/tasks/*.yml"
# - vars: "**/vars/*.yml"
# - meta: "**/meta/main.yml"
- yaml: "**/*.yaml-too"
I'm seeing this issue with ansible-lint 6.10.0 even after adding the community.general
collection to my requirements.yml
file.
WARNING Unable to load module community.general.timezone at roles/system_config/tasks/main.yml:46 for options validation
WARNING Unable to resolve FQCN for module community.general.timezone
Here's an example job:
https://github.com/smrealms/seed-server/actions/runs/3783650542/jobs/6432363437
And here's what my requirements.yml
looks like:
---
collections:
- community.general
roles:
- src: geerlingguy.docker
version: 5.2.1
- src: hifis.unattended_upgrades
version: v1.12.2
Am I doing something wrong here? Thanks!
@hemberger
see https://docs.ansible.com/ansible/latest/galaxy/user_guide.html
Installing both roles and collections from the same requirements file will not work when specifying a custom collection or role install path. In this scenario the collections will be skipped and the command will process each like ansible-galaxy role install would.
and old version https://docs.ansible.com/ansible/2.9/galaxy/user_guide.html
While both roles and collections can be specified in one requirements file, they need to be installed separately. The ansible-galaxy role install -r requirements.yml will only install roles and ansible-galaxy collection install -r requirements.yml -p ./ will only install collections.
I think, maybe not installed colections.
need command like a ansible-galaxy collections install -r requirements.yml
right?
@officel Thanks for the pointers! I should have clarified that this is only an issue in the GitHub Action (locally, where I do have community.general
installed, everything is working fine). I'm not sure what ansible-lint
is doing under the hood to discover community collections. Do I need to run ansible-galaxy collections install -r requirements.yml
in the GHA workflow before I run ansible-lint
?
I see. Then it does not seem necessary.
@hemberger
I checked again. I misunderstood because I am not good at English. Sorry 🙇
ansible-lint-action uses creator-ee with docker. https://github.com/ansible/ansible-lint-action/blob/main/action.yml
creator-ee automatically reads requirements.yml in the top directory of the repository. The requirements.yml it is based on does not contain the community.general collection we need. https://github.com/ansible/creator-ee/blob/main/_build/requirements.yml
So when we use this ansible-lint-action, we need to put the collections in our requirements.yml.
No problem.
@hemberger Did you get this working? I've modified my action to install the requirements from the root like so:
name: Ansible Deployment
on:
workflow_dispatch:
jobs:
linting:
name: List Ansible Files
runs-on: ubuntu-22.04
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- name: Install Ansible
run: sudo apt-get install -y ansible
- name: Install Ansible-Galaxy Requirements
run: ansible-galaxy install -r requirements.yaml
- name: List Installed Ansible-Galaxy Requirements
run: ansible-galaxy collection list
- name: Linting
uses: ansible/ansible-lint-action@dd225474d15635904348151b9e694472ce0f62a8
with:
path: ansible/
But I'm still getting FQCN resolution failures.
---
collections:
- name: community.general
- name: community.docker
Did you get this working?
No, I haven't been able to get this to work either. Since ansible-lint is running in a docker container, my suspicion is that it will require changes to the creator-ee image or ansible-lint itself. https://github.com/ansible/ansible-lint-action/blob/dd225474d15635904348151b9e694472ce0f62a8/action.yml#L24-L27
Bummer. @ssbarnea Any ideas on this one?
You must have a requirements.yml file on your repo so linter could install these deps itself! Running galaxy before the action does not help as that is not inside the action container.
You must have a requirements.yml file on your repo so linter could install these deps itself! Running galaxy before the action does not help as that is not inside the action container.
Thanks for the quick response! In my example job above (https://github.com/ansible/ansible-lint-action/issues/99#issuecomment-1365487875), I have community.general
in my repo's requirements.yml file, but I still get the FQCN warning about it.
Fair point. Can we override the path to avoid pushing the galaxy file into root?
@Schachte You can pass path
variable but that is not alone enough. You also need to create a config file at the desired location in order to convince linter to consider that path as project directory. Otherwise it will fallback to git and that will report the parent patch as being the project.
Was there ever a solution to this? I have a chicken-egg-problem: when I put community.general into the requirements.yml I get an error that
ERROR! Failed to find the collection dir deps: The collection galaxy.yml path '/Users/nik/.cache/ansible-compat/bec60e/collections/ansible_collections/community/general/galaxy.yml' does not exist.
If I do not have community.general in the requirements.yml I get errors with playbooks that use modules from community.general that the dependencies are not in the requirements.yml.
I've solved it by reverting to https://github.com/ansible/ansible-lint-action@v6.11.0 from current @main - which uses 6.14.4.
Same issue here, when i move back to v6.11.0 as suggested by @barzog it solves the issue but now my linter is buggy because of a loop-var-prefix[wrong] false positive, that seems to be fixed in a newer version of the linter...
It works fine locally, but FQCN seems to error in this actions.
playbooks
local run(it's ok)
Could you please tell me how to do this? 🙇