New user: need support to exclude some files from directory for clang operation in yaml with ansible with zuul jobs

I need support to exclude some files from directory for clang operation in yaml with ansible with zuul jobs.

purpose: I need to exclude unwanted files (e.g. exclude 4 / 10 files) from directory to perform clang operation in zuul jobs which is written in yaml with ansbile as below example:

I need help to correct this if there is any syntax issue / any other minor mistakes.

- job:
    name: clang-component1
    parent: base-clang-tools
    required-projects:
      - name: apps-project
    vars:
      app_name: component1
      repo_root: “{{ zuul.projects[‘url/apps-project’].src_dir }}”
      workspace: “{{ repo_root }}/inside1/component1”
      filtered_cpp_files: >-
      {{
        src_cpp_files.files | # something is missed?
        selectattr(‘path’, ‘search’, ‘^(?!.(file1.cpp|file2.cpp|file3.cpp))..cpp$’) |
        map(attribute=‘path’) |
        list
      }}
      filtered_hpp_files: >-
      {{
        src_cpp_files.files | # something is missed?
        selectattr(‘path’, ‘search’, ‘^(?!.(file1.hpp|file2.hpp|file3.hpp))..hpp$’) |
        map(attribute=‘path’) |
        list
      }}
      additionalsourcefiles: >-
      {{
        ‘dir1/src/*.hpp’,
        'dir1/inc/*.cpp’,
        ‘dir1/inc/*.hpp’
      }}
      runclangfiles: >-
      {{
        filtered_cpp_files + filtered_hpp_files + additionalsourcefiles
      }}
      analysis_code_paths: “{{ runclangfiles }}”

Thank you in advance!

Could you edit you post to use fenced code blocks to make it easier to read?

1 Like

Hello @chris

I have updated my post, thank you for your suggestion.

1 Like

I can’t help with clang or zuul but I’d suggest using the debug module to check the lists, for example:

- name: Debug filtered_cpp_files
  ansible.builtin.debug:
    msg: >-
      {{
        src_cpp_files.files | # something is missed?
        selectattr(‘path’, ‘search’, ‘^(?!.(file1.cpp|file2.cpp|file3.cpp))..cpp$’) |
        map(attribute=‘path’) |
        list
      }}

- name: Debug filtered_hpp_files
  ansible.builtin.debug:
    msg: >-
      {{
        src_cpp_files.files | # something is missed?
        selectattr(‘path’, ‘search’, ‘^(?!.(file1.hpp|file2.hpp|file3.hpp))..hpp$’) |
        map(attribute=‘path’) |
        list
      }}
1 Like

thank you,

where I can see debug messages with what value it is considering for this msg, in general?

basically here I need to exclude few files from directory and stored those file path in variable (if really needed as per Ansible syntax, format…) and use that files for further operation (can be anything, run clang, static_code, etc.)

I would like to understand and correct above code.

NOTE: it is configure in CI, not locally

You should see the debug results wherever you see the output from Ansible running I guess?

1 Like