Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Create file if not exists? #91

Closed

Description

@httpete

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

Activity

  1. skx commented on Feb 11, 2022

    @skx
    Owner

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

  2. self-assigned this
    on Feb 11, 2022
  3. added
    invalidThis doesn't seem right
    questionFurther information is requested
    on Feb 11, 2022
  4. httpete commented on Feb 15, 2022

    @httpete
    Author

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

  5. skx commented on Feb 15, 2022

    @skx
    Owner

    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" ,
           ... }
    
  6. added a commit that references this issue on Feb 15, 2022
    b3f0c46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem rightquestionFurther information is requested

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址