-1

I have a playbook

---
- hosts: all
  gather_facts: True
  tasks:
    - action: debug msg="time = {{ ansible_date_time }}"

Which returns the full json representation for each machine. How do I further filter that within the playbook such that I only get the iso8601_basic_short part

[root@pjux playbooks]# ansible --version
ansible 2.1.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

TASK [debug] *******************************************************************

ok: [10.99.97.222] => { "msg": "time = {u'weekday_number': u'2', u'iso8601_basic_short': u'20160906T182117', u'tz': u'BST', u'weeknumber': u'36', u'hour': u'18', u'year': u'2016', u'minute': u'21', u'tz_offset': u'+0100', u'month': u'09', u'epoch': u'1473182477', u'iso8601_micro': u'2016-09-06T17:21:17.761900Z', u'weekday': u'Tuesday', u'time': u'18:21:17', u'date': u'2016-09-06', u'iso8601': u'2016-09-06T17:21:17Z', u'day': u'06', u'iso8601_basic': u'20160906T182117761843', u'second': u'17'}" }

ok: [10.99.97.216] => { "msg": "time = {u'weekday_number': u'2', u'iso8601_basic_short': u'20160906T182117', u'tz': u'BST', u'weeknumber': u'36', u'hour': u'18', u'year': u'2016', u'minute': u'21', u'tz_offset': u'+0100', u'month': u'09', u'epoch': u'1473182477', u'iso8601_micro': u'2016-09-06T17:21:17.938563Z', u'weekday': u'Tuesday', u'time': u'18:21:17', u'date': u'2016-09-06', u'iso8601': u'2016-09-06T17:21:17Z', u'day': u'06', u'iso8601_basic': u'20160906T182117938491', u'second': u'17'}" }

techraf
  • 64,883
  • 27
  • 193
  • 198
Paul J
  • 69
  • 2
  • 6

1 Answers1

2

Have you tried {{ ansible_date_time.iso8601_basic_short }}?

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Works many thanks, I got hung up on trying to use a colon as not dealt with json before. SOLVED – Paul J Sep 07 '16 at 08:28