【问题标题】:How to add export statements to bash_profile with Augeas and Puppet如何使用 Augeas 和 Puppet 将导出语句添加到 bash_profile
【发布时间】:2018-10-23 15:45:51
【问题描述】:

我让 Puppet + Augeas 在 bash_profile 中分配变量值,但是我还没有找到从文件中导出变量的方法。

  augeas { "bash_profile-${user}-${name}":
    incl    => "/home/${user}/.bash_profile",
    lens    => 'Shellvars.lns',
    changes => "set ${variable_name} '\"${literal_value}\"'",
  }

结果:

# .bash_profile 
variable="value"

但我需要的是:

# .bash_profile 
export variable="value"
# or
variable="value"
export variable

这个Puppet ticket 似乎应该指向正确的方向,但我不知道如何编写导出语句

【问题讨论】:

  • 您是否考虑过使用提供内容的.erb 直接管理文件?
  • 我愿意,但我不想覆盖现有内容

标签: puppet augeas


【解决方案1】:

Augeasproviders 项目为此有一个 shellvar type

shellvar { "bash_profile-${user}-${name}":
  ensure   => exported,
  target   => "/home/${user}/.bash_profile",
  variable => $variable_name,
  value    => $literal_value,
}

还有管理引用或数组值的选项。

【讨论】:

  • 很好——下次我会看看这些
【解决方案2】:

这似乎可以解决问题:

  augeas { "bash_profile-${user}-${name}":
    incl    => "/home/${user}/.bash_profile",
    lens    => 'Shellvars.lns',
    changes => [
      "set ${variable_name} '\"${literal_value}\"'",
      "set ${variable_name}/export ''",
      ],
  }

【讨论】:

    猜你喜欢
    • 2016-11-28
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 2014-08-14
    • 1970-01-01
    相关资源
    最近更新 更多