1

I cannot figure out, how to deal with case when I have 2 resources managed by puppet, depending on each other (one is parent of another), and both are set to be absent. Test case below. Directories doesn't exists already, but puppet complains about creating files there. How to fix this manifest?

$ find . -type f
./modules/test/manifests/init.pp
./modules/test/files/b/x
./modules/test/files/b/z
./modules/test/files/b/y
./manifests/site.pp
./test.pp
$ cat manifests/site.pp 
## site.pp

node default {
    include test
}
$ cat modules/test/manifests/init.pp 
## init.pp

class test {
    file { 'dir1':
        ensure  => absent,
        path    => '/tmp/a',
        before  => File['dir2'],
    }

    file { 'dir2':
        ensure  => absent,
        path    => '/tmp/a/b',
        source  => 'puppet:///modules/test/b',
        force   => true,
        purge   => true,
        recurse => true,

    }
}
$ puppet apply --modulepath ./modules manifests/site.pp
Notice: Compiled catalog for localhost in environment production in 0.11 seconds
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/z20140523-14751-1qpqnds-9'
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/z20140523-14751-1qpqnds-9'
Wrapped exception:
cannot generate tempfile `/tmp/a/b/z20140523-14751-1qpqnds-9'
Error: /Stage[main]/Test/File[/tmp/a/b/z]/ensure: change from absent to file failed: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/z20140523-14751-1qpqnds-9'
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/y20140523-14751-1bxpkko-9'
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/y20140523-14751-1bxpkko-9'
Wrapped exception:
cannot generate tempfile `/tmp/a/b/y20140523-14751-1bxpkko-9'
Error: /Stage[main]/Test/File[/tmp/a/b/y]/ensure: change from absent to file failed: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/y20140523-14751-1bxpkko-9'
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/x20140523-14751-1u3y3dl-9'
Error: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/x20140523-14751-1u3y3dl-9'
Wrapped exception:
cannot generate tempfile `/tmp/a/b/x20140523-14751-1u3y3dl-9'
Error: /Stage[main]/Test/File[/tmp/a/b/x]/ensure: change from absent to file failed: Could not set 'file' on ensure: cannot generate tempfile `/tmp/a/b/x20140523-14751-1u3y3dl-9'
Notice: Finished catalog run in 0.14 seconds

EDIT:

Full context:

## init.pp

class test {

    $is_master  = false

    if $is_master {
        $file_ensure        = present
        $directory_ensure   = directory
    } else {
        $file_ensure        = absent
        $directory_ensure   = absent
    }

    file { 'dir1':
        ensure  => $directory_ensure,
        path    => '/tmp/a',
        before  => File['dir2'],
    }

    file { 'dir2':
        ensure  => $directory_ensure,
        path    => '/tmp/a/b',
        source  => 'puppet:///modules/test/b',
        force   => true,
        purge   => true,
        recurse => true,
    }
}

You cannot remove dir1, because it'll fail on master, I need to make it works on master and slave.

1

Remove the File['dir2'] resource completely, and change File['dir1'] to:

file { 'dir1':
    ensure  => absent,
    path    => '/tmp/a',
    recurse => true,
    force   => true,
}

With your code, you're trying to remove /tmp/a, before you remove /tmp/a/b. If you remove /tmp/a first, then /tmp/a/b can't even exist. You want the reverse order.

However, that is not even necessary. If you're removing /tmp/a, there's no reason to create a resource definition to remove anything inside it.

  • It's not so simple, because it's only a small piece of whole code. It have to be two separate resources. – fazie May 23 '14 at 14:10
  • @fazie Then perhaps you should tell us exactly what you're doing so we don't have to guess. – Patrick May 23 '14 at 14:20
  • Ok, I've edited my question, and added more background. – fazie May 23 '14 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.