簡體   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