如何使用saltstack添加包回购和密钥到apt?

时间:2017-09-14 16:22:55

标签: debian salt-stack apt

我只是SaltStack的初学者。我可以看到有一个pkgrepo模块可以用来设置一个包repo,以便从中安装包。

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.pkgrepo.html

给出的一个例子是:

base:
  pkgrepo.managed:
    - humanname: Google Chrome
    - name: deb http://dl.google.com/linux/chrome/deb/ stable main
    - dist: stable
    - file: /etc/apt/sources.list.d/chrome-browser.list
    - require_in:
      - pkg: google-chrome-stable
    - gpgcheck: 1
    - key_url: https://dl-ssl.google.com/linux/linux_signing_key.pub

我不明白的是我在哪里放上面的代码?我在/srv/salt/top.sls和其他状态的.sls文件中尝试过,但这是不对的。怎么做?

1 个答案:

答案 0 :(得分:2)

您基本上想知道如何使用SaltStack状态。这在https://docs.saltstack.com/en/latest/topics/tutorials/starting_states.html记录。

要测试此代码,您必须:

  • 创建一个包含代码的新sls文件,例如testrepo.sls
  • 使用salt命令执行此状态。

示例:

salt 'hostname.domainname' state.sls testrepo

其中hostname.domainname是您要配置的minion(saltstack客户端)的名称,由salt-key报告。

在给定的示例中,base是州名。它必须是独一无二的。因此,base是在文档中使用的一个非常糟糕的选择,因为它可能会让您对顶部sls文件语法感到困惑,如下所示:https://docs.saltstack.com/en/latest/ref/states/top.html

因此,为了安装google-chrome,举个例子,您需要创建一个状态文件,如下所示:

google_chrome_repository:
  pkgrepo.managed:
    - humanname: Google Chrome
    - name: deb http://dl.google.com/linux/chrome/deb/ stable main
    - dist: stable
    - file: /etc/apt/sources.list.d/chrome-browser.list
    - gpgcheck: 1
    - key_url: https://dl-ssl.google.com/linux/linux_signing_key.pub

google-chrome-stable:
  pkg.installed:
    - require:
      - pkgrepo: google_chrome_repository

请注意,如果您有多个要从此存储库安装的程序包,我认为在这里更有意义的必要声明从require_in更改为require。这里记录了必要条件:https://docs.saltstack.com/en/latest/ref/states/requisites.html