Ask Your Question
2

File resource runs despite exec unless

asked 2017-10-11 20:56:57 -0600

scottnl gravatar image

updated 2017-10-11 21:31:55 -0600

I'm Applying a local manifest to test an exec and file resource:

class test_file {   
        exec { "touch /tmp/testfile":
            path    => ["/bin", "/usr/bin", "/sbin", "/usr/sbin"],
            unless  => "test -d /tmp 2>/dev/null",
        }
    file { "/tmp/success":
        mode => "0777",
        owner => "root",
        group => "staff",
        source => "file:///Users/Shared/success",
        require   => Exec["touch /tmp/testfile"],
            }
}

What I expect to happen: the exec runs and exits because the unless statement returns 0, so the file resource never runs. so neither file is created in /tmp

What Actually happens: The file resource always runs, and copies the "success" file to /tmp

I've run this on macOS 10.11 and 10.12 with both puppet agent 4.10 and 5.3.2 ... with the same results. I'm simply trying to run a conditional that says don't copy a file if some command exits successful. Any insights or directions would be appreciate.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2017-10-12 07:18:07 -0600

DarylW gravatar image

You can’t conditionally run a file resource like that, the ‘requires’ param is just for ordering. Your only options are to create the file with an exec, or check on the file with a factor fact and then set its presence/absence contitionally in your puppet code, or you could wire a custom type/provider that wraps the file resource, and give it onlyif/unless.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-11 20:56:57 -0600

Seen: 124 times

Last updated: Oct 12