title: Ansible - Append local date_time to a file name
body: <p>Ansible Experts,
  I am trying to create a play-book, that retrieves current configuration of Cisco routers and switches, then to save it to a file. I also need the file name to append with local datetime. Like ansible_date_time field in facts, i did not see any in routers/switches gather_facts data. So i tried to get this information from local host where i run ansible. As it is not included in the host inventory file, i had to add a localhost.
  The problem i face is, i am successfully getting date_time from ansible_facts, however this registered value seems to be not working with filename. I am guessing it is due to the &quot;when&quot; statement in my tasks. Not sure.</p>
  <pre><code>TASK [Display Ansible date_time fact and register] *******************************************************************************************
  skipping: [LAB_TKYAT07EXTRT03]
  skipping: [LAB_TKYAT07EXTRT04]
  ok: [localhost] =&gt; {
      &quot;msg&quot;: &quot;2021-06-18&quot;
  }
  skipping: [LAB_TKYAT07SPN01]
  skipping: [LAB_TKYAT07SPN02]
  skipping: [LAB_TKYAT07LF01]
  skipping: [LAB_TKYAT07LF02]
  skipping: [LAB_TKYAT07LF03]
  skipping: [LAB_TKYAT07LF04]
  </code></pre>
  <p>My output filename looks &quot;LAB_TKYAT07LF01{'skip_reason': u'Conditional result was False', 'skipped': True, 'changed': False}_showrunn.txt&quot;</p>
  <pre><code>--- 
  - 
    connection: network_cli
    gather_facts: false
    hosts: LAB_ALL
  
    tasks:   
      - 
        name: gather facts from apps
        setup:
          gather_subset:
            - hardware
        when: ansible_connection == 'local'   
        tags: linux
  
      - 
        name: &quot;Display Ansible date_time fact and register&quot;
        debug: 
          msg: &quot;{{ ansible_date_time.date }}&quot;
        when: ansible_connection == 'local'  
        register: currenttime
        tags: linux
  
      - 
        name: &quot;retrieve show runn all from Nexus &quot;
        nxos_command: 
          commands: 
          - command: show runn all
        register: nexus_output
        when: ansible_network_os == 'nxos'
      
      - 
        name: &quot;Save Nexus output to outputs folder&quot;
        copy:
          content: &quot;{{ nexus_output.stdout[0] }}&quot;
          dest: &quot;./outputs/{{ inventory_hostname }}{{ currenttime }}_showrunn.txt&quot;
        when: ansible_network_os == 'nxos'   
  
      - 
        name: &quot;retrieve show runn all from Routers &quot;
        ios_command: 
          commands: 
          - command: show runn all
        register: ios_output
        when: ansible_network_os == 'ios'
  
      - 
        name: &quot;Save IOS output to outputs folder&quot;
        copy:
          content: &quot;{{ ios_output.stdout[0] }}&quot;
          dest: &quot;./outputs/{{ inventory_hostname }}{{ currenttime }}_showrunn.txt&quot;
        when: ansible_network_os == 'ios'  
  </code></pre>