Is there a way to run a recipe, on a remote server, on demand without adding it to the run list?
For example with knife.
TIA
Is there a way to run a recipe, on a remote server, on demand without adding it to the run list?
For example with knife.
TIA
chef-client -o recipe[foo]
Thanks! But that does not work (I’m running it from a chef management server):
# knife ssh host100 -x ec2-user “sudo chef-client -o recipe[single-run::hello]”
WARN: Overridden Run List: [recipe[single-run::hello]]
com resolving cookbooks for run list: [“single-run::hello”]
…
com [2018-07-29T00:43:22+00:00] WARN: Skipping final node save because override_runlist was given
…
com Chef Client finished, 0/0 resources updated in 04 seconds
OK, first. Stop trying to shove sudo syntax manually through the “knife ssh” command,. For example, the “sudo” command would normally be used with the “-c” option to feed it a complex command. But hey, the “knife ssh” command actually has a “knife ssh --sudo” option.
So, work your way backwards through the steps if you want to check your syntax, and discover that the “recipe[sing-run-hello]” option needs its own quote markmarks, due to the left and right square brackets. I think what you need is:
knife ssh --sudo "chef-client -o 'recipe[single-run::hello]'"
And next time, do test your syntax with an echo command:
knife ssh --sudo "echo chef-client -o 'recipe[single-run::hello]'"
Or possibly something like:
knife ssh "echo sudo -c \"chef-client -o 'recipe[single-run::hello]'\""
And then:
knife ssh "echo sudo -c \"chef-client -o 'recipe[single-run::hello]'\""
There is no --sudo flag:
# knife --sudo
invalid option: --sudo
# knife -v
Chef: 14.2.0
You certainly can pass sudo in the command and override the runlist… example:
[brad@hornet:~] $ knife ssh -x ec2-user <TARGET HOST> -i ~/.aws/us-east-2.pem "sudo chef-client -o recipe[chef-client]" -m
<TARGET HOST> Starting Chef Client, version 14.3.37
<TARGET HOST> [2018-07-29T04:07:58+00:00] WARN: Run List override has been provided.
<TARGET HOST> [2018-07-29T04:07:58+00:00] WARN: Original Run List: [recipe[chef-client], recipe[cop_apache2]]
<TARGET HOST> [2018-07-29T04:07:58+00:00] WARN: Overridden Run List: [recipe[chef-client]]
<TARGET HOST> resolving cookbooks for run list: ["chef-client"]
...
...
You’re right, there is no “–sudo” option. I was just looking at the “knife bootstrap” command. Why "“knife bootstrap” has it, and “knife ssh” does not, I’ve no idea.
knife ssh works with sudo rather than --sudo. Ex. knife ssh hostname sudo