0

I have a question about ruby/chef, I am creating a recipe that will setup a cron job once we chef-client the node and I am getting a syntax error when I run my kitchen test

The following block of code is part of my recipe

  action node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["enabled"] = ? :create : :delete
  minute node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["minute"]
  hour node["hadoop_temp"]["scripts"]["cron"]["clean_teamp"]["hour"]
  day node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["day"]
  month node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["month"]
  weekday node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["weekday"]

the following block is part of my attributes.

  #Run the cron every day at 12AM cleans /temp
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["enabled"] = false
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["minute"] = "0"
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["hour"] = "0"
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["day"] = "*"
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["month"] = "*"
  default["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["weekday"] = "*"

when I run my kitchen test I am getting the following error.

   SyntaxError
   -----------
   /tmp/kitchen/cache/cookbooks/hadoop_temp/recipes/clean_temp.rb:25: syntax error, unexpected '?'
   ..."hadoop_temp"]["enabled"] = ? :create : :delete

I do not understand boolean 100% in ruby what I want to accomplish is if the entry exist create but if in the future I want to delete I just have to switch the attribute to true.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
Alex-
  • 125
  • 2
  • 10

1 Answers1

0

You could learn about the ternary operator in rubylearn about the ternary operator in ruby

I did took the = sign out of the recipe action. now it looks like:

    action node["hadoop_temp"]["scripts"]["cron"]["clean_temp"]["enabled"] ? :create : :delete

Thank you @StephenKing the test passed

Community
  • 1
  • 1
Alex-
  • 125
  • 2
  • 10