Is there a way to know if I'm launching a playbook from AWX or from the command line?
According Ansible Tower documentation Launch a Job Template
Tower automatically adds the following variables to the job environment: ...
tower_job_launch_type
: The description to indicate how the job was started:
manual
: Job was started manually by a user.
In other words, if specific variables are not set the job was not triggered from Ansible Tower (automatically).
A short example: assert
– Asserts given expressions are true together with Providing default values can be used to
- name: Check if job was triggered manually or automatically
assert:
that:
- "'manual' not in tower_job_launch_type | default('manual')"
fail_msg: "Job was triggered manually in Ansible Tower or via Ansible Engine!"
quiet: true