I want to use the "date" command output as an environment variable.
Suppose
- tasks:
- name: Getting start date
shell: date +%d%b%Y:%H:%M
register: start_date
- debug:
vars: start_date.stdout
environment:
start_date_env: start_date.stdout
- name: Echo my_env_var
shell: echo $start_date_env
register: some
- debug:
var: some.stdout
O/P
changed: [host1]
cmd: date +%d%b%Y:%H:%M
stdout: 05Aug2018:09:30
TASK [Echo my_env_var] ***********************************************************************************************************************
cmd: echo $start_date_env
ok: [host1] => {
"some.stdout": ""
I want to run date command in the above mentioned format on the remote host, then save the variable possibly as environment on the target host. This is because I've to use this variable to grab some data at the end of execution of 3-4 playbooks.. the data will depend upon start_time of playbooks and end_time of playbook. Basically two environment variable start_time and end_time which I can use in the end
In short, is it possible to set output of one command executed on host as environment variable one the same host in ansible
ansible_date_time.dateYou could use that to simplify things. The only caveat is that gather-fact must be set to true.