With Ansible Runner, how to reset the `env/cmdline` file that is generated post execution?

I am using ansible-runner with a Click CLI application. I am using the run function to execute my playbooks in the project directory.

I am using some skip-tags to execute specific tasks and skips some other.

Programatically,

from ansible_runner import run

conf = {
  'private_data_dir': '.', # in root dir
  'playbook': 'some_playbook.yml',
}

if some_click_option:
    conf['cmdline'] = '--skip-tags=tagA'

out, rc = run(**conf)

The core logic is sound and works, however the root directory creates the env/cmdline file.

Since he env/cmdline contains the --skip-tags=tagA persists the playbook seems to skips the tasks upon execution even when my CLI doesn’t set the specific option.

Any smart way to purge the env/cmdline post execution?

The only way I can come around is remove the file based on the return code rc value.

The way this is generally handled is by using process_isolation, and/or directory_isolation_base_path. If using a non-container process-isolation such as bubblewrap, then the project dir is copied into the directory_isolation_base_path, to prevent modification of the source project dir.

Outside of this using bubblewrap, or container based isolation, you could implement the same behavior by copying the project to a tempdir, and use that, rather than directly executing against the source project dir. You would then also have to clean up that tempdir yourself afterwards.