creating a directory

Hi,

I have tried this a bunch of different ways, I'm just posting my last
version. Wondering if this is working as expected. I want to create
a directory using the command module and it will create it if I take
the second play out of the playbook. But when the directory doesn't
exsist and both plays are in the playbook it fails on the copy. Is
this a bug or am I missing some basic thing? I have tried this with
and without the creates option and with and with out a chdir.

Thanks,
James

sheepchase:tasks jmarcus$ cat backup.citrusleaf.conf.yml
- hosts: CL801
  user: jmarcus
  sudo: True

  tasks:
   - name: Make sure that the ansible_backup directory exsists
     action: command mkdir /etc/citrusleaf/AnsibleBackup
creates=/etc/citrusleaf/ansible_backup

  tasks:
   - name: Copy citrusleaf.conf before changing it
     action: shell cp /etc/citrusleaf/citrusleaf.conf
/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.`date +%F.%H:%M:%S`

sheepchase:tasks jmarcus$ ansible-playbook backup.citrusleaf.conf.yml
-u jmarcus -K
sudo password:

PLAY [CL801] *********************

GATHERING FACTS *********************
ok: [cl801.domain.net]

TASK: [Copy citrusleaf.conf before changing it] *********************
failed: [cl801.domain.net] => {"changed": true, "cmd": "cp
/etc/citrusleaf/citrusleaf.conf
/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.`date +%F.%H:%M:%S` ",
"delta": "0:00:00.005314", "end": "2012-08-26 09:07:02.950212", "rc":
1, "start": "2012-08-26 09:07:02.944898", "stderr": "cp: cannot create
regular file `/etc/citrusleaf/AnsibleBackup/citrusleaf.conf.2012-08-26.09:07:02':
No such file or directory", "stdout": ""}

PLAY RECAP *********************
cl801.domain.net : ok=1 changed=0 unreachable=0 failed=1

Would anyone like to guess what's different about these two directory paths?

mkdir /etc/citrusleaf/AnsibleBackup creates=/etc/citrusleaf/ansible_backup

That's right, they aren't the same.

you can also be using the file module with state=directory.

Further, in 0.7, the copy and template module have a backup mode.

sorry I corrected that. I copied into the email before changing that,
I'll give state= a try.

Thanks,
james

Hi James,

You also have two "tasks: " sections, is there a reason for that? I’m not sure that’s valid syntax, just use one “tasks:” and then put your actions below. You’re also missing the — which I believe YAML requires. And try using the file with state=directory: