# Setting check mode in ansible-playbook execution with env var

**URL:** <https://forum.ansible.com/t/setting-check-mode-in-ansible-playbook-execution-with-env-var/40114>\
**Category:** Get Help\
**Tags:** ansible\
**Created:** [February 7, 2025, 4:34am UTC](https://forum.ansible.com/t/setting-check-mode-in-ansible-playbook-execution-with-env-var/40114 "2025-02-07T04:34:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamroddo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/iamroddo/32/321_2.png) [@iamroddo](https://forum.ansible.com/u/iamroddo)\
**Post date:** [February 7, 2025, 4:34am UTC](https://forum.ansible.com/t/setting-check-mode-in-ansible-playbook-execution-with-env-var/40114/1 "2025-02-07T04:34:31Z")

</div>

Is there a way to trigger a playbook to be executed with check mode using an environment variable? To put it another way, can an env var be set to be the equivalent of the flag `--check` on `ansible-playbook`?

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [February 7, 2025, 4:02pm UTC](https://forum.ansible.com/t/setting-check-mode-in-ansible-playbook-execution-with-env-var/40114/2 "2025-02-07T16:02:56Z")

</div>

It’s only configurable as a CLI arg or the `check_mode` [keyword](https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html). Individual plays can configure `check_mode` using an environment variable though.

```auto
- hosts: all
  check_mode: "{{ lookup('env', 'ANSIBLE_CHECK_MODE', default='false') | bool }}"

```

If your play uses the special variable ansible\_check\_mode, keep in mind it only reflects the value of `--check`, not `check_mode`.

```auto
- hosts: all
  vars:
    play_check_mode: "{{ lookup('env', 'ANSIBLE_CHECK_MODE', default='false') | bool }}"
  check_mode: "{{ play_check_mode }}"
  tasks:
  - action: ...
    when:
      - ansible_check_mode is falsy
      - play_check_mode is falsy

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 9, 2025, 4:03pm UTC](https://forum.ansible.com/t/setting-check-mode-in-ansible-playbook-execution-with-env-var/40114/3 "2025-03-09T16:03:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
