简体   繁体   中英

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?

The --check option executes ansible in dry run mode. You need to remove the --check flag, in order to actually execute the play on the remote hosts. The correct command is:

ansible-playbook -i hosts update.yml

Please see below link

Ansible Dry Run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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