Skip to content

Commit 8a3a27a

Browse files
committed
add a workaround for running with --noop or --tags
This fixes errors like: Error: Could not prefetch rabbitmq_user provider 'rabbitmqctl': Command rabbitmqctl is missing ...under the following conditions: * The client does not yet have rabbitmq installed. * Puppet is run with --noop or a specific set of --tags that does not include rabbitmq resources. On a fresh client in normal operation, the sequence of events is: 1. Install the rabbitmq package. 2. Start the service. 3. Run the prefetch for resources which use rabbitmqctl (e.g. rabbitmq_user). 4. Apply the resources (or not, if they already exist). On a fresh client running with --noop or tags, the sequence of events is: 1. (nothing) 2. (nothing) 3. Run the prefetch, but fail. To work around this, assume that if rabbitmq management commands are not found, then rabbitmq is not installed at all, thus all corresponding resources are not present. On a normal run, the rabbitmq packages will be installed before resources which need rabbitmq commands, so the workaround is never triggered. This is _probably_ not an ideal fix, but it's the best I have.
1 parent 8854872 commit 8a3a27a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/puppet/provider/rabbitmq_cli.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def self.rabbitmqctl_list(resource, *opts)
5454
['-q']
5555
end
5656
rabbitmqctl("list_#{resource}", *list_opts, *opts)
57+
rescue Puppet::MissingCommand
58+
# rabbitmqctl is not present. Normally we would have installed a package
59+
# that provides rabbitmqctl by now, but if we're running under --noop or
60+
# with a restrictive set of tags, the package may not have been installed.
61+
# Return an empty string to avoid error. This may give false positives for
62+
# resources under --noop!
63+
Puppet.debug('rabbitmqctl command not found; assuming rabbitmq is not installed')
64+
''
5765
end
5866

5967
def self.rabbitmq_running

lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def self.plugin_list
1818
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
1919
# explicitly enabled.
2020
rabbitmqplugins('list', '-e', '-m')
21+
rescue Puppet::MissingCommand
22+
# See note about Puppet::MissingCommand in:
23+
# lib/puppet/provider/rabbitmq_cli.rb
24+
Puppet.debug('rabbitmqplugins command not found; assuming rabbitmq is not installed')
25+
''
2126
end
2227
# Split by newline.
2328
lines = list_str.split(%r{\n})

0 commit comments

Comments
 (0)