Several commands in one line for cronjob in hiera (Puppet) yaml

I have hieradata yaml file with a lot of options and some cronjobs I want to add one more cronjob that contain several bash commands in it with quotes:

hbase_test:
      cron: '*/5 * * * *'
      user: 'root'
      command: '(date && echo "describe \'my_table\'; exit" | hbase shell) >> hbase_test.log 2>&1;'
      flock: true

But this doesn't work - puppet fails to load such yaml. I also tried next way:

command: "(date && echo \"describe 'my_table'; exit\" | hbase shell) >> hbase_test.log 2>&1;"

Puppet is ok, hbase starts successfully, but fails:

describe my_table; exit
NameError: undefined local variable or method `my_table' for #<Object:0xf9f041c>

The right command must be:

describe 'my_table'; exit

I lost quotes! And I don't know how to escape them in right way. I also tried

command:>
  (date && echo "describe 'my_table'; exit" | hbase shell) >> hbase_test.log 2>&1;

But cron doesn't start.

1 answer

  • answered 2021-03-03 16:10 Shane Bishop

    You need a space between your : and your >. This is what you want:

    command: >
      (date && echo "describe 'my_table'; exit" | hbase shell) >> hbase_test.log 2>&1;
    

    You can see how the YAML parses to JSON here.