0

I am trying to build a custom resource which would in turn use another of my custom resource as part of its action. The pseudo-code would look something like this

customResource A
property component_id String

action: doSomething do
  component_id = 1 if component_id.nil?
  node.default[component_details][component_id] = ''

  customResource_b "Get me component details" do
    comp_id component_id
    action :get_component_details
  end

  Chef::log.info("See the output computed by my customResourceB")
  Chef::log.info(node[component_details][component_id])
end

Thing to note: 1. The role of customResource_b is to make a PS call to a REST web service and store the JSON result in node[component_details][component_id] overriding its value. I am creating this attribute node on this resource since I know it will be used later one, hence avoiding compile time issues.

Issues I am facing: 1. When testing a simple recipe that calls this resource in chef-client, the code in the resource gets executed to the last log line and after that the call to customResource_b is made. Which is something I am not expecting to happen.

Any advice would be appreciated. I am also quite new to Chef so any design improvements are also welcome

Draco Ater
  • 20,820
  • 8
  • 62
  • 86

1 Answers1

0

there is no need to nest chef resources, rather use chef idompotance, guards and notification.

and as usualy, you can always use a condition to decide which cookbook\recipe to run.

Mr.
  • 9,429
  • 13
  • 58
  • 82