I ran this:
- hosts: dbserver
  remote_user: jlouthan
  tasks:
      - name: Get current timestamp
        local_action: command bash -c "date +%Y-%m-%d.%H%M"
        register: timestamp
        run_once: true

      - debug: var=timestamp.stdout

      - name: Get current datestamp
        local_action: command bash -c "date +%Y-%m-%d"
        register: datestamp
        run_once: true

      - debug: var=datestamp.stdout

      - name: Backup Stag Database
        mysql_db: state=dump name=dbname target=~jlouthan/dbname.{{ 
datestamp }}.sql
become: yes
        become_method: sudo
- name: See the the Stag DB backup
shell: ls -la ~jlouthan/ | grep {{ timestamp }}
register: dumpstag
      - debug: var=dumpstag.stdout_lines

      - name: Make sure that the Stag DB Backups look good before you 
continue
        pause:

And got this:
[jlouthan@ansible-server Playbooks]$ ansible-playbook 
test-backup-Client-staging-db.yml
SUDO password:

PLAY [dbserver] 
**************************************************************



GATHERING FACTS 
***************************************************************


ok: [dbserver]



TASK: [Get current timestamp] 
*************************************************
changed: [dbserver -> 127.0.0.1]

TASK: [debug var=timestamp.stdout] 
********************************************
ok: [dbserver] => {
    "var": {
        "timestamp.stdout": "2016-04-22.1507"
    }
}

TASK: [Get current datestamp] 
*************************************************
changed: [dbserver -> 127.0.0.1]

TASK: [debug var=datestamp.stdout] 
********************************************
ok: [dbserver] => {
    "var": {
        "datestamp.stdout": "2016-04-22"
    }
}

TASK: [Backup Stag Database] 
**************************************************
failed: [dbserver] => {"failed": true}
msg: this module requires key=value arguments (['state=dump', 
'name=dbname', 'target=~jlouthan/dbname.{changed:', 'True,', 'end:', 
'2016-04-22 15:07:30.816204,', 'stdout:', '2016-04-22,', 'cmd:', '[bash,', 
'-c,', 'date +%Y-%m-%d],', 'rc:', '0,', 'start:', '2016-04-22 
15:07:30.810278,', 'stderr:', ',', 'delta:', '0:00:00.005926,', 
'invocation:', '{module_name:', 'ucommand,', 'module_complex_args:', '{},', 
'module_args:', 'ubash -c "date +%Y-%m-%d"},', 'stdout_lines:', 
'[2016-04-22],', 'warnings:', '[]}.sql'])

FATAL: all hosts have already failed -- aborting

PLAY RECAP 
********************************************************************
           to retry, use: --limit 
@/home/jlouthan/test-backup-Client-staging-db.retry

dbserver                  : ok=5    changed=2    unreachable=0    failed=1

What am I doing wrong?

On Thursday, April 21, 2016 at 6:46:45 PM UTC-5, Felix Fontein wrote:
>
> Hi Joe, 
>
> you could add a task 
>
> - name: Get current timestamp 
>   local_action: command bash -c "date +%Y-%m-%d.%H%M" 
>   register: now 
>   run_once: true 
>
> (or something similar adapted to your local environment) before your 
> dump task and then use {{ now }} in the next tasks to always get the 
> same timestamp. 
>
> Best, 
> Felix 
>
>
>
> On Thu, 21 Apr 2016 08:45:53 -0700 (PDT) 
> Joe Louthan <[email protected] <javascript:>> wrote: 
>
> > Hello, 
> > 
> > In my deployments, I tend to do db backups and dump them into 
> > filenames containing a timestamp like so: 
> > 
> > mysqldump dbname | gzip -9c > ~/dbname.`date +%Y-%m-%d.%H%M`.sql.gz ; 
> > ls -la ~/ | grep `date +%Y-%m-%d` 
> > 
> > As you can see, when the dump is done, I want to see the resulting 
> > file just to eyeball it and make everything looks right. 
> > 
> > (To answer future questions: we date time stamp our backup files so 
> > that we can keep them for an extended period of time.) 
> > 
> > I would like to write something like this: 
> > 
> > - hosts: dbserver 
> >   remote_user: jlouthan 
> >   tasks: 
> >       - name: Backup Prod Database 
> >         shell: mysqldump dbdump | gzip -9c > ~jlouthan/dbdump.`date 
> > +%Y-%m-%d`.sql.gz 
> >         become: yes 
> >         become_method: sudo 
> > 
> >       - name: Check to see if the dbdump has been successfully created 
> >         wait_for: path=~jlouthan/dbdump.`date +%Y-%m-%d`.sql.gz 
> > 
> > 
> > Is there any chance that Ansible would be able to pick up on 
> > backticks or is there a better way? 
> > 
>

-- 
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/04fc2437-16f3-40fd-9ae2-2faef850ba4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to