How to retrieve arguments to ansible-playbook from ansible?

Hi

As part of our deployment we are saving a file
/etc/deployment_status.json onto remote nodes:

  vars:
    deployment_status:
      version: "{{ our_version }}"
      date: "{{ ansible_date_time.iso8601 }}"
      deployer: "{{ lookup('env', 'USER') }}"
      ansible: "{{ lookup('pipe', 'ansible --version') }}"

  pre_tasks:
    - name: Write deployment status to /etc/deployment_status.json
      copy:
        content: "{{ deployment_status | to_nice_json }}"
        dest: /etc/deployment_status.json
      tags: always,deployment_status

This has proven to be helpful.
Now I would like to also include information about how
ansible-playbook was invoked, for instance which tags were used, or
what hosts the deployment was limited to.
Is there any way of knowing what arguments ansible-playbook was run
with, from within ansible?

thx!

Hello,

Is this what you are looking for?

https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html

Nuno Jordão

Yes, that goes a long way.
But I realized we call ansible-playbook from a shell wrapper, so I
used "${@}" in there instead.

thx!