How to get details about a user running an Ansible Tower job

Hi all,

I’ve two questions:

  1. Is there a way to know the details about a user who runs playbooks (job template/workflow)? I’d propose that module “tower_user” might do that, it just can be extended with some output like it does “stat” module.

`

playbook.yml

  • tower_user:
    username: jobowner
    register: jobowner_stat

  • debug:
    msg: |
    Username: {{ jobowner_stat.username }}
    Email: {{ jobowner_stat.email }}
    Is_superuser: {{ jobowner_stat.superuser }}
    First name: {{ jobowner_stat.first_name }}
    Last name: {{ jobowner_stat.last_name }}

`

Or if there is something already implemented, it would be great to know about this.

  1. How can I know that a playbook is run by Ansible Tower? For example, I’m writing a playbook on a local machine and I need to run additional tasks like “Get the owner of a job which runs the playbook” above.

Thank you,
Dmitrii

Tower returns a handful of variables containing info about a job execution:

https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html

  • tower_job_id: The Job ID for this job run
  • tower_job_launch_type: The description to indicate how the job was started:
    • manual: Job was started manually by a user.
    • relaunch: Job was started via relaunch.
    • callback: Job was started via host callback.
    • scheduled: Job was started from a schedule.
    • dependency: Job was started as a dependency of another job.
    • workflow: Job was started from a workflow job.
    • sync: Job was started from a project sync.
    • scm: Job was created as an Inventory SCM sync.
    • tower_job_template_id: The Job Template ID that this job run uses
  • tower_job_template_name: The Job Template name that this job uses
  • tower_user_id: The user ID of the Tower user that started this job. This is not available for callback or scheduled jobs.
  • tower_user_name: The user name of the Tower user that started this job. This is not available for callback or scheduled jobs.
  • tower_schedule_id: If applicable, the ID of the schedule that launched this job
  • tower_schedule_name: If applicable, the name of the schedule that launched this job
  • tower_workflow_job_id: If applicable, the ID of the workflow job that launched this job
  • tower_workflow_job_name: If applicable, the name of the workflow job that launched this job. Note this is also the same as the workflow job template.
    Is this what you’re looking for?