To clear up, using local_action does not affect 'controller only'
actions like set_fact/group_by/add_hosts/etc.
Also using local_action will ONLY use the localhost 'connection vars',
the rest of the vars will belong to the inventory_hostname (this is
true for all delegation).
Aside from the solution above, another option, if you gathered facts
from localhost:
- name: Gathering and setting Facts for this deploy
set_fact:
date_time: '{{ hostvars['localhost']['ansible_date_time]['date']
+ '_' + hostvars['localhost']['ansible_date_time]['time'] }}'
@Kai your suggestion is greater however, the output is in the format:
Mon 24 Jul 21:23:08 BST 2017
I was looking for it to be in the format: 2017-07-24_02:26:08 - as I will be using that to create the directory names.
@Brian I think your suggestions looks like it’s going to do exactly what I want, however when I ran it, I kept getting the following errors:
“failed”: true,
“msg”: “the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘dict object’ has no attribute ‘ansible_date_time’\n\nThe error appears to have been in ‘/usr/playbooks/website-playbooks/roles/websites-backup/tasks/main.yml’: line 14, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gathering and setting Facts for this deploy\n ^ here\n”
}
to retry, use: --limit @/usr/playbooks/website-playbooks/websites-backup.retry
I tried a few modifications of it, but I didn’t have much luck…