How to retrieve arguments to ansible-playbook from ansible?

17 views
Skip to first unread message

Dick Visser

unread,
Jul 15, 2020, 10:04:54 AM7/15/20
to ansible...@googlegroups.com
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!

--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Nuno Jordão

unread,
Jul 15, 2020, 11:29:04 AM7/15/20
to ansible...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwNMgorhYQNUqub1FqPjo9H_XQCzzLB5pvkOCK%2Bx5SMgbw%40mail.gmail.com.

Dick Visser

unread,
Jul 15, 2020, 12:15:38 PM7/15/20
to ansible...@googlegroups.com
Yes, that goes a long way.
But I realized we call ansible-playbook from a shell wrapper, so I
used "${@}" in there instead.

thx!
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEAA%3Dtut09AGcXU_95dnaTG0ouYdTsu9WR7N%2BAAgmLqLbs5-zw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages