1

I would like to add an automatic syntax check (as CI process) for all the Ansible playbooks in my project, using ansible-lint. There are playbooks in several directories in the project, so I thought of using something like locate *.yml. However, the problem is that there are some other YAML files in my project, which are not Ansible playbooks, and therefore I would not want ansible-lint to test those files(as it will always fail).

Is there any way to distinguish between ansible playbooks and regular YAML files?

ChikChak
  • 936
  • 19
  • 44

1 Answers1

2

I assume all your ansible-playbooks contain something like - hosts, perhaps you can use grep for that search query. And then perform the linter on the found files with | xargs ansible-lint.

So forget the .yaml file extension, but take another approach. You'll figure it out :)

Kevin C
  • 4,851
  • 8
  • 30
  • 64
  • If I'm trying to do something like `grep -rwl '- hosts:'` I get an error: `grep: invalid option -- ' '`, but without the `-` it works fine. Any way to include the `-`? – ChikChak Jul 20 '19 at 17:43
  • 1
    `grep -rwl -- '- hosts:'` – error404 Jul 20 '19 at 17:56
  • My plays tend to begin with `- name: something` rather than `- hosts: something`, so I have to search without the hyphen. That picks up inventories too. But then inventories can be identified as having `all:` near the beginning. – Adam J Richardson Dec 03 '22 at 12:39