繁体   English   中英

如何使用Ansible更新远程主机

[英]How to update Remote Host Using Ansible

我要在每个远程服务器上运行以下命令:

sudo apt-get update -y
sudo apt-get upgrade -y 
sudo apt-get dist-upgrade -y

在运行任何内容之前,登录服务器时,我会收到以下消息:

Welcome to Ubuntu 18.10 (GNU/Linux 4.18.0-10-generic x86_64)
...

...
132 packages can be updated.
79 updates are security updates.

然后,我运行以下剧本:

---
- hosts: myserver
  remote_user: root
  become: yes
  become_method: sudo
  tasks:

    - name: "Update packages"
      apt:
        update_cache: yes # apt-get update
        upgrade: full

    - name: "Update dist"
      apt:
         upgrade: dist

    - name: UpdateRaw
      shell: apt-get update -y
    - name: UpgradeRaw
      shell: apt-get upgrade -y
    - name: DistUpgradeRaw
      shell: sudo apt-get dist-upgrade -y

使用命令

ansible-playbook -i hosts update.yml --check

但是当我回到服务器时,仍然看到相同的消息:

Welcome to Ubuntu 18.10 (GNU/Linux 4.18.0-10-generic x86_64)
...

...
132 packages can be updated.
79 updates are security updates.

如何使用Ansible更新服务器?

--check选项在空运行模式下执行。 您需要删除--check标志,以便在远程主机上实际执行播放。 正确的命令是:

ansible-playbook -i hosts update.yml

请看下面的链接

Ansible空跑

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM