简体   繁体   English

如何使用Ansible更新远程主机

[英]How to update Remote Host Using Ansible

I each of my remote servers I want to run the equivalent of: 我要在每个远程服务器上运行以下命令:

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

Before running anything, when I login in the Server I get the following messages: 在运行任何内容之前,登录服务器时,我会收到以下消息:

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

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

Then, I run the following playbook: 然后,我运行以下剧本:

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

using the command 使用命令

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

But when I go back to server I still see the same message: 但是当我回到服务器时,仍然看到相同的消息:

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

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

How do I update my server using ansible? 如何使用Ansible更新服务器?

The --check option executes ansible in dry run mode. --check选项在空运行模式下执行。 You need to remove the --check flag, in order to actually execute the play on the remote hosts. 您需要删除--check标志,以便在远程主机上实际执行播放。 The correct command is: 正确的命令是:

ansible-playbook -i hosts update.yml

Please see below link 请看下面的链接

Ansible Dry Run Ansible空跑

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

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