skx / marionette

Something like puppet, for the localhost only.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create file if not exists?

httpete opened this issue · comments

I see the file module won't create the file if it isn't there - any way to tell it to?

That should work, and does in my tests. Here's an example input that demonstrates three ways of using the file module:

file {
    target => "1.txt",
    content => "I am created",
}

file {
    target => "2.txt",
    source_url => "https://example.com/",
}


file {
    target => "3.txt",
    source => "/etc/passwd",
}

Before running I have no text-files, after I do:

frodo ~/Repos/github.com/skx/marionette $ ls *.txt
contains.txt
frodo ~/Repos/github.com/skx/marionette $ ./marionette fi
file/    file.in  
frodo ~/Repos/github.com/skx/marionette $ ./marionette file.in 
frodo ~/Repos/github.com/skx/marionette $ ls *.txt
1.txt  2.txt  3.txt  contains.txt

Which type of file operation are you using? A copy? A template? A literal content attempt, or a remote HTTP/HTTPS fetch?

Does running with -debug show any obvious error(s) ?

What I see is that if target is /down/a/subdir it won't mkdir -p the trail.

Ahah, that was the missing detail!

If you try to create a file in a directory that does not exist then I would expect that to fail and would not regard that as a bug.

Maybe there should be better error-handling to report upon it though.

Something like this is what you want:

# create the directory
directory{ name => "mkdir-/down/a",  target => "/down/a/subdir" }

# fill it ..
file{ ... 
       require => "mkdir-/down/a" ,
       ... }