SaltStack:/ etc / sudo:/ bin / systemctl vs / usr / bin / systemctl

自从几周以来,我们使用SaltStack进行configurationpipe理。

如何处理systemctl的分发特定位置?

  • 在Ubuntu上: /bin/systemctl
  • 在SuSE上: /usr/bin/systemctl

此刻,我将两行添加到sudoers文件中:

 etc_sudoers: file.blockreplace: - name: /etc/sudoers - marker_start: "# START managed etc_sudoers -DO-NOT-EDIT-" - marker_end: "# END managed zone etc_sudoers --" - content: | some_user ALL = NOPASSWD: /bin/systemctl restart apache2 some_user ALL = NOPASSWD: /usr/bin/systemctl restart apache2 {% endfor %} - append_if_not_found: True - backup: '.bak' - show_changes: True 

….有没有更简单的解决scheme?

不幸的是,没有简单或自动的方法。 但是根据Salt最佳实践 ,使用map.jinja文件有更好的方法。

在Salt Formulas中,将特定于平台的数据(如程序包名称和文件系统path)放置在名为map.jinja的文件中,这是与状态文件并列的。

使用它将确保你的状态的模块化,使他们能够运行,无论小兵的操作系统。

下面是你的map.jinja文件在你提交的场景中的一个例子。 它将通过OS系列过滤小人,并根据它设置variables:

 {% set systemctl = salt['grains.filter_by']({ 'Debian': { 'location': '/bin/systemctl' }, 'Suse': { 'location': '/usr/bin/systemctl' } } %} 

现在您需要将其导入到状态文件中,并使用之前定义的variables:

 {% from "systemctl/map.jinja" import systemctl with context %} etc_sudoers: file.blockreplace: - name: /etc/sudoers - marker_start: "# START managed etc_sudoers -DO-NOT-EDIT-" - marker_end: "# END managed zone etc_sudoers --" - content: some_user ALL = NOPASSWD: {{ systemctl.location }} restart apache2 - append_if_not_found: True - backup: '.bak' - show_changes: True 

有关更多信息,请查看文档的模块性和查找表会话。