Also, just as an FYI, this can be achieved without calling the date command:

---
- hosts: all
  tasks:
    - set_fact:
        datestamp: "{{ ansible_date_time.date }}"
        timestamp: "{{ '%s.%s%s'|format(ansible_date_time.date,
ansible_date_time.hour, ansible_date_time.minute) }}"

    - debug:
        msg: "{{ item }}"
      with_items:
        - "{{ datestamp }}"
        - "{{ timestamp }}"



On Mon, Apr 25, 2016 at 8:40 AM, Joe Louthan <[email protected]> wrote:

> That's it! Thank you!
>
> To avoid being "that guy", here is the working playbook:
>
> ---
> - hosts: dbserver
>   remote_user: jlouthan
>   tasks:
>       - name: Get current timestamp
>         local_action: command bash -c 'date +%Y-%m-%d.%H%M'
>         # Consider switch this to a shell module with date command
>         register: timestamp
>         run_once: true
>
>       - debug: var=timestamp.stdout
>
>       - name: Get current datestamp
>         local_action: command bash -c 'date +%Y-%m-%d'
>         # Consider switch this to a shell module with date command
>         register: datestamp
>         run_once: true
>
>       - debug: var=datestamp.stdout
>
>       - name: Backup dbname Database
>         mysql_db: "state=dump name=dbname target=~jlouthan/dbname.{{
> timestamp.stdout }}.sql"
>         become: yes
>         become_method: sudo
>
>       - name: See the DB Backups
>         shell: ls -la ~jlouthan/ | grep {{ datestamp.stdout }}
>         register: dumpdb
>
>       - debug: var=dumpdb.stdout_lines
>
>       - name: Make sure that the dbname DB Backups look good before you
> continue
>         pause:
>
> This playbook:
>
>    1. *Gets current date and time stamps from the remote machine (as
>    oppose to the local machine that is running Ansible*. Something to
>    keep in mind if you have servers in different timezones) - *Note: the
>    debug lines for date and time stamps are merely there for me to see what
>    stamp should I be seeing*
>    2. *Backup database using the timestamp within the resulting file name*
>    3. *Double check using just the datestamp (as oppose to the fulltime
>    stamp) and making sure that the backup looks good*
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b3befc8a-0ea3-4f17-bc63-dfc04f7d1ac8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b3befc8a-0ea3-4f17-bc63-dfc04f7d1ac8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Matt Martz
@sivel
sivel.net

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9RiyYxoqtObVd-XErA-jEExuqDjEk6UmuOeE1mCu74Sg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to