# Ansible-lint to exclude specific rules

**URL:** <https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240>\
**Category:** Get Help\
**Tags:** ansible, ansible-project, ansible-devel, ansible-lint\
**Created:** [February 13, 2025, 9:27am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240 "2025-02-13T09:27:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![selvi](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@selvi](https://forum.ansible.com/u/selvi)\
**Post date:** [February 13, 2025, 9:27am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/1 "2025-02-13T09:27:00Z")

</div>

Hi,

I have put different playbooks within several directories in the gitlab repository and would like to execute ansible-lint to validate my playbooks. In one of the playbooks, I have utilized an undefined variable (intended to provide the value as an environmental variable), which caused ansible-lint to fail with the error shown below.

```auto
 lint_output='ttps://ansible.readthedocs.io/projects/lint/rules/syntax-check/yntax-check[specific]: The field '\''hosts'\'' has an invalid value, which includes an undefined variable.. '\''target_host'\'' is undefined
playbook.yml:2:3

```

Despite attempting multiple options to bypass this error, I couldn’t succeed. Could anyone provide any suggestions to resolve this issue?

---

<div class="post-metadata">

**Author:** ![jrglynn2](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jrglynn2](https://forum.ansible.com/u/jrglynn2)\
**Post date:** [February 13, 2025, 4:26pm UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/2 "2025-02-13T16:26:34Z")

</div>

Last June I opened an issue on the lint GitHub for this: [False positive: hosts variable not defined · Issue #4225 · ansible/ansible-lint · GitHub](https://github.com/ansible/ansible-lint/issues/4225)

---

<div class="post-metadata">

**Author:** ![selvigp](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/selvigp/32/4977_2.png) [@selvigp](https://forum.ansible.com/u/selvigp)\
**Post date:** [February 13, 2025, 4:54pm UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/3 "2025-02-13T16:54:03Z")

</div>

Yes, i have seen that issue. It is still open. Do we have any workaround where we can ignore this errors while running ansible-lint, because of this i am getting failed error.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [February 14, 2025, 3:53am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/4 "2025-02-14T03:53:34Z")

</div>

Maybe try adding this to your lint config?

```auto
extra_vars:
  target_host: foo

```

---

<div class="post-metadata">

**Author:** ![area51coder](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@area51coder](https://forum.ansible.com/u/area51coder)\
**Post date:** [February 14, 2025, 5:55am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/5 "2025-02-14T05:55:54Z")

</div>

Hello Selvi, I am learning ansible on my lab, can you send me your playbook which is generating errors while running ansible-lint. i want to have a look to reproduce the error and try to fix.

---

<div class="post-metadata">

**Author:** ![selvigp](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/selvigp/32/4977_2.png) [@selvigp](https://forum.ansible.com/u/selvigp)\
**Post date:** [February 14, 2025, 8:40am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/6 "2025-02-14T08:40:38Z")

</div>

Sure, I will do.

```auto
---
- name: Running ad-hoc command on selected redhat-servers
  hosts: "{{ wanted_host | default('localhost') }}"
  become: true
  gather_facts: true
  tasks:
    - name: Running ad-hoc command {{ command | default() }} on {{ wanted_host | default('localhost') }} linux-server
      ansible.builtin.command: "{{ command | default() }}"
      register: output
      changed_when: false

    - name: output
      ansible.builtin.debug:
        var: output.stdout_lines

```

---

<div class="post-metadata">

**Author:** ![selvigp](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/selvigp/32/4977_2.png) [@selvigp](https://forum.ansible.com/u/selvigp)\
**Post date:** [February 14, 2025, 8:40am UTC](https://forum.ansible.com/t/ansible-lint-to-exclude-specific-rules/40240/7 "2025-02-14T08:40:54Z")

</div>

Sure, I will check it.

Thanks
