如何检查SaltStack状态文件中服务器上不存在包?

问题描述 投票:0回答:3

我正在尝试在 Ubuntu 计算机上使用 saltstack 版本 2015.5.2 自动安装 Aerospike 数据库。

以下是我想要自动化的手动安装的过程。 (为了简单起见,我只提关键步骤)

  1. 下载 Aerospike

    wget -O aerospike.tgz
    http://aerospike.com/download/server/latest/artifact/ubuntu12

  2. 提取包装中的内容

    tar -xvf aerospike.tgz

  3. 安装 Aerospike 服务器和工具

    cd aerospike-server-community-3.5.15-ubuntu12.04
    ./asinstall

  4. 启动 Aerospike

    /etc/init.d/aerospike start

第 3 步执行实际安装,其中包括安装 2 个软件包:aerospike-server-communityaerospike-tools

现在在 saltstack 状态文件中,我想检查这两个包是否已存在于服务器上,在这种情况下,不要执行步骤 3 中的

./asinstall
命令。

我如何将该条件纳入我的自动化流程中?

salt-project aerospike
3个回答
2
投票

我建议你在继续之前阅读盐的必备条件,因为你可以在那里找到很多有趣的东西。

此外,在我看来,您真正需要的是:

UNLESS
,因为如果您的系统上已经有这些软件包,则不应安装它们。除非可以与
pkg
关键字一起使用,但对您来说
rpm -q package_name
可能也同样有效。

它应该看起来像这样:

start_process:
  cmd.run:
    - name: 'write here your command'
    - unless:
      - rpm -q package1,package2

1
投票

我想对答案提供一点小小的评论,但我的声誉不允许我这样做,所以我为此提前道歉。

这一行:

- rpm -q package1,package2

实际上应该是:

- rpm -q package1 package2

0
投票

根据 Salt 的版本,您可以使用 Jinja 模板:

{% if not salt["pkg.version"]("aerospike-server") %}
asinstall:
  cmd.run:
    - name: /tmp/aerospike-server-community-3.5.15-ubuntu12.04/asinstall
    - cwd: aerospike-server-community-3.5.15-ubuntu12.04
    - require_in:
      - service: aerospike
{% end if %}

或者在运行时进行相同的检查:

asinstall:
  cmd.run:
    - name: /tmp/aerospike-server-community-3.5.15-ubuntu12.04/asinstall
    - cwd: aerospike-server-community-3.5.15-ubuntu12.04
    - unless:
      - fun: pkg.version
        name: aerospike-server

或者通过文件是否存在进行检查:

asinstall:
  cmd.run:
    - name: /tmp/aerospike-server-community-3.5.15-ubuntu12.04/asinstall
    - cwd: /tmp/aerospike-server-community-3.5.15-ubuntu12.04
    - creates: /usr/bin/aerospike-server  # or whatever it creates
© www.soinside.com 2019 - 2024. All rights reserved.