在Hiera内部做基本数学


布偶的表弟派大星丶
2024-12-18 02:23:57 (2月前)


我正在尝试根据自定义事实和基本模数在hiera中设置crontab的工作日,但我甚至无法弄清楚它是否可行。

我想做点什么:

的cron作业:
命令:“做……

3 条回复
  1. 0# ࿏自ོ༾由ོ༽人͙⃡⌇ | 2019-08-31 10-32



    我不确定我是否遵循用例,但你可能会使用它

    inline_epp

    要么

    inline_template

    使它看起来像这个功能存在。



    例如:



    1.   # In real usage this would be the result of a hiera lookup
    2. $simple_lookup_result = 9 % 7
      $simple_evaluated = inline_template(“<%= ${simple_lookup_result} %>”)

    3. exec { simple’:
      command => “/bin/echo $simple_evaluated”,
      logoutput => true,
      }

    4. Again, hiera

      $complex_lookup_result = sprintf(“The value is %i”, 9 % 7)’
      $complex_evaluated = inline_template(“<%= ${complex_lookup_result} %>”)

    5. exec { complex’:
      command => “/bin/echo $complex_evaluated”,
      logoutput => true,
      }

    6. </code>


    结果如下:




    1. $ puppet apply eval.pp
      Notice: Compiled catalog for box in environment production in 0.06 seconds
      Notice: /Stage[main]/Main/Exec[simple]/returns: 2
      Notice: /Stage[main]/Main/Exec[simple]/returns: executed successfully
      Notice: /Stage[main]/Main/Exec[complex]/returns: The value is 2
      Notice: /Stage[main]/Main/Exec[complex]/returns: executed successfully
      Notice: Applied catalog in 0.05 seconds

    2. </code>


    请记住,Hiera可以进行插值

    变量

    要么

    Hiera查找

    ,查找也可以在代码中完成

    inline_epp

    要么

    inline_template

    最终会评估。




    注:这是一个示例,除非您信任您的用户并且非常喜欢头痛,否则您不应将Hiera输入传递给shell命令。
    </强>


  2. 1# 日耀九洲 | 2019-08-31 10-32



    不,这是不可能的。请记住YAML是公正的

    数据

    ,而不是代码。



    Hiera确实使用Interpolation Tokens提供了一些转换,但只有

    两个功能

    你可以使用这些,没有算术。


登录 后才能参与评论