Hi Joe,

> 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

as you correctly note here, the variable you need is not timestamp, but
timestamp.stdout.

(I forgot the .stdout in my original mail.)

>       - name: Backup Stag Database
>         mysql_db: state=dump name=dbname target=~jlouthan/dbname.{{ 
> datestamp }}.sql

Here you have to write {{ datestamp.stdout }} instead of
{{ datestamp }}; otherwise, instead of just the datestamp, the whole
dict will be appended, which results in the error message you get below.

> 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'])

Here you can see that {{ datestamp }} was replaced by:

{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"}

which is NOT what you want :)

Best,
Felix



> 
> 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? 
> > >   
> >  
> 


-- 
Felix Fontein -- [email protected] -- https://felix.fontein.de/

-- 
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/20160422230035.7fe73a6c%40fontein.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to