Ask Your Question
0

resource tidy does not notify exec resource at all [closed]

asked 2017-10-10 10:54:20 -0600

mknl gravatar image

updated 2017-10-11 08:37:00 -0600

Hi,

I have some tidy+notify code which looks like this:

tidy { '/parent-path-tidy-should-do-something':
        recurse => 3,
        matches => [ 'search-string1', 'search-string2', 'search-string3'],
        rmdirs  => false,
        notify => [ Exec['my-exec1'], Exec['my-exec2'] ];
    }


exec {'my-exec1':
    cwd     => '/sbin',
    path    => '/sbin',
    command => 'my-command1',
    refreshonly => true,
}

exec {'my-exec2':
    cwd     => '/sbin',
    path    => '/sbin',
    command => 'my-command2',
    refreshonly => true,
}

It can also be tested with one exec, but this was already discussed in another question I posted so it should basically work.

Now I checked the logs after manual puppet run (puppet agent --test) and I saw that it does not really notify my execs after executing tidy ressource. Log looks like this:

Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for <my-test-host>
Notice: /Stage[main]/<my module>::<my_class>/Tidy[<parent-path-tidy-should-do-something>]: Tidying File[<full-path-file1>]
Notice: /Stage[main]/<my module>::<my_class>/Tidy[<parent-path-tidy-should-do-something>]: Tidying File[<full-path-file2>]
Notice: /Stage[main]/<my module>::<my_class>/Tidy[<parent-path-tidy-should-do-something>]: Tidying File[<full-path-file3>]
...
...
-> more tidying log entries <-
Info: Applying configuration version '<version_number>'
Notice: /Stage[main]/<my module>::<my_class>/File[<full-path-file1>]/ensure: removed
Notice: /Stage[main]/<my module>::<my_class>/File[<full-path-file2>]/ensure: removed
Notice: /Stage[main]/<my module>::<my_class>/File[<full-path-file3>]/ensure: removed
...
...
-> more tidy related file log entries <-
Notice: /Stage[main]/<my module2>::<my_class2>/File[<full-path-file0815>]/ensure: defined content as '{md5}e585d4b0105e6fdbea479beff2505133'
...
...

So after the last tidy related file-ensure-removed-log-entry I expected the notify/exec. E.g . like in the linked question:

Notice: /Stage[main]/Main/Exec[my-exec1]: Triggered 'refresh' from 1 events
Notice: /Stage[main]/Main/Exec[my-exec2]: Triggered 'refresh' from 1 events

But it does not happen. :-/ I don't see my mistake and I was wondering why the notify does not work? Is there anybody out there who can help me with this? Any way to debug this? tidy works perfect here for me only the notify is missing.

Thanks in advance

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mknl
close date 2017-10-12 03:31:59.818698

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-10-12 02:44:42 -0600

mknl gravatar image

updated 2017-10-12 03:31:00 -0600

The answer which does not make me very happy is: It is a bug. https://tickets.puppetlabs.com/browse...

Before a colleague pointed me to the bug link above I prepared a little test (see listing at the end of this post). Test 1 in debug mode showed (only the interesting part):

Debug: Finishing transaction 30608920
Debug: Loaded state in 0.04 seconds
Debug: Loaded state in 0.04 seconds
Debug: /Stage[main]/Is_testing/Tidy[tidy_test_resource]/notify: subscribes to Exec[test_exec]
Notice: /Stage[main]/Is_testing/Tidy[tidy_test_resource]: Tidying File[/tmp/puppet_tests/test_dir/test_file_search1]
Notice: /Stage[main]/Is_testing/Tidy[tidy_test_resource]: Tidying File[/tmp/puppet_tests/test_dir/test_subdir1/test_file_search2]
Notice: /Stage[main]/Is_testing/Tidy[tidy_test_resource]: Tidying File[/tmp/puppet_tests/test_dir/test_subdir1/test_sub_dir2/test_file_search3]
Info: Applying configuration version '1507793189'
Debug: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_subdir1/test_file_search2]: Removing existing file for replacement with absent
Notice: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_subdir1/test_file_search2]/ensure: removed
Debug: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_subdir1/test_sub_dir2/test_file_search3]: Removing existing file for replacement with absent
Notice: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_subdir1/test_sub_dir2/test_file_search3]/ensure: removed
Debug: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_file_search1]: Removing existing file for replacement with absent
Notice: /Stage[main]/Is_testing/File[/tmp/puppet_tests/test_dir/test_file_search1]/ensure: removed
Debug: Finishing transaction 36509500
Debug: Storing state
Debug: Stored state in 0.06 seconds
Notice: Finished catalog run in 0.11 seconds

So there is only one log entry for the subcribe:

Debug: /Stage[main]/Is_testing/Tidy[tidy_test_resource]/notify: subscribes to Exec[test_exec]

but no notify happend. You can perform the second test (with file) on your own if you don't trust me. ;-)

Maybe in a newer puppet version it works:

Debug: Runtime environment: puppet_version=3.8.6, ruby_version=2.0.0, run_mode=user, default_encoding=UTF-8

My code to test and confirm that it is a bug:

## preparation
###########################################################
mkdir /tmp/puppet_tests/
cd /tmp/puppet_tests/
puppet module generate tester-is_testing --skip-interview

## not sure why this is necessary but otherwise 
## puppet apply did not work (it did not find the test class)
mv tester-is_testing is_testing

## create some random, files which should be cleaned up
## Test 1 by tidy Test 2 by file (only one file as example)
####################################
mkdir test_dir
touch test_dir/test_file_search1
mkdir test_dir/test_subdir1
touch test_dir/test_subdir1/test_file_search2
mkdir test_dir/test_subdir1/test_sub_dir2
touch test_dir/test_subdir1/test_sub_dir2/test_file_search3
####################################

vi is_testing/manifests/init.pp
## --> cleanup comments and insert test code between class is_testing { }

## Test 1
####################################
tidy { 'tidy_test_resource':
    path    => '/tmp/puppet_tests/test_dir',
    recurse => 3,
    matches => [ '*search1', '*search2', '*search3'],
    rmdirs  => false,
    notify => Exec['test_exec'];
}

exec {'test_exec':
    cwd     => '/bin',
    path    => '/bin',
    command => 'echo "test_exec_executed" > /tmp/puppet_tests/test_exec.log',
    refreshonly => true;
}
####################################

## Test 2
####################################
file { 'file_test_resource':
    path    => '/tmp/puppet_tests/test_dir/test_file_search1',
    ensure  => absence,
    notify => Exec['test_exec'];
}

exec {'test_exec':
    cwd     => '/bin',
    path    => '/bin',
    command => 'echo "test_exec_executed" > /tmp/puppet_tests/test_exec.log',
    refreshonly => true;
}
####################################

## Test 3 (dirty workaround)
####################################
exec {'trigger_exec':
        cwd     => '/bin',
        path    => '/bin',
        command => 'echo "Oh that is evil, I like it :-)" > /dev/null 2>&1',
        onlyif  => 'test -e /tmp/puppet_tests/test_dir/test_file_search1',
        notify  => [ Tidy['tidy_test_resource'], Exec['test_exec ...
(more)
edit flag offensive delete link more

Comments

Added a dirty workaournd -> Test 3 Topic will be closed now.

mknl gravatar imagemknl ( 2017-10-12 03:31:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-10-10 10:54:20 -0600

Seen: 69 times

Last updated: Oct 12