【问题标题】:Ansible - List of Linux security updates needed on remote serversAnsible - 远程服务器上所需的 Linux 安全更新列表
【发布时间】:2020-03-10 12:02:06
【问题描述】:

我想运行一个能够准确报告远程服务器是否需要安全更新的剧本。 Ansible 服务器 = Centos 7,远程服务器 Amazon Linux。

远程服务器会在启动时突出显示如下内容:

https://aws.amazon.com/amazon-linux-2/ 安全需要 8 个包,46 个可用 运行“sudo yum update”以应用所有更新。

为了证实这一点,我整理了一本剧本,从许多来源(如下)拼凑而成,它们确实在一定程度上执行了该功能。它确实建议远程服务器是否需要安全更新,但没有说明这些更新是什么?

- name: check if security updates are needed
  hosts: elk
  tasks:
    - name: check yum security updates
      shell: "yum updateinfo list all security"
      changed_when: false
      register: security_update

    - debug: msg="Security update required"
      when: security_update.stdout != "0"

    - name: list some packages
      yum: list=available

然后,当我运行更新安装手册时:

- hosts: elk
  remote_user: ansadm
  become: yes
  become_method: sudo
  tasks:

    - name: Move repos from backup to yum.repos.d
      shell: mv -f /backup/* /etc/yum.repos.d/
      register: shell_result
      failed_when: '"No such file or directory" in shell_result.stderr_lines'

    - name: Remove redhat.repo
      shell: rm -f /etc/yum.repos.d/redhat.repo
      register: shell_result
      failed_when: '"No such file or directory" in shell_result.stderr_lines'

    - name: add line to yum.conf
      lineinfile:
        dest: /etc/yum.conf
        line: exclude=kernel* redhat-release*
        state: present
        create: yes

    - name: yum clean
      shell: yum make-cache
      register: shell_result
      failed_when: '"There are no enabled repos" in shell_result.stderr_lines'

    - name: install all security patches
      yum:
       name: '*'
       state: latest
       security: yes
       bugfix: yes
       skip_broken: yes

安装后,您会得到类似于下面的内容(顺便说一句 - 这些是来自不同服务器的输出)

https://aws.amazon.com/amazon-linux-2/ 无需包裹以确保安全; 37 包可用 运行“sudo yum update”以应用所有更新。

但如果我再次运行我的列表安全更新手册 - 它会给出误报,因为它仍然报告需要安全更新?

PLAY [检查是否需要安全更新] ************************************

任务[收集事实] ****************************************** *************** 好的:[10.10.10.192]

任务 [检查 yum 安全更新] **************************************** ****** 好的:[10.10.10.192]

任务[调试] ******************************************* ************************ 好的:[10.10.10.192] => { "msg": "需要安全更新" }

TASK [列出一些包] ***************************************** ************* 好的:[10.10.10.192]

播放回顾 ************************************************ ************************ 10.10.10.192 : ok=4 changed=0 unreachable=0 failed=0 skipped=0 saved=0 ignored=0

[ansadm@ansible 剧本]$

我需要在 playbook 中省略/包含哪些内容以反映安装更新后的更改?

提前致谢:)

【问题讨论】:

    标签: linux ansible


    【解决方案1】:

    所以我在我的系统上本地运行了你的 yum 命令,我得到了以下结果。

    45) local-user@server:/home/local-user> yum updateinfo list all security
    Loaded plugins: ulninfo
    local_repo                                                                                                                                                                   | 2.9 kB  00:00:00
    updateinfo list done
    

    现在我们的系统可能在这里有不同的输出,但这将有助于我的解释。整个命令的输出保存到您的寄存器中,但是当该命令的输出不完全为“0”时,您的条件说明运行。

    因此,除非您将该响应与某些 awk 或 sed 相提并论,否则它会响应任何更多文本,即调试任务总是会触发的字符“0”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多