惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园_首页
Google DeepMind News
Google DeepMind News
博客园 - Franky
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
罗磊的独立博客
IT之家
IT之家
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
腾讯CDC
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

Posts on Noah Bailey

How to turn anything into a router Deploy to Cloudfront from GitHub using OpenID Connect Backup Postgres databases with Kubernetes CronJobs The spelling error made 200 billion times a day Restarting Kubernetes pods using a CronJob You've just bought a new domain. Now what? Who Sawed My Motherboard??? Linux on the P8 Aliexpress Mini Laptop Recovering Mysql/Mariadb after a nasty crash Using EXIF data to pick my next lens Converting and developing RAW photos on Linux automatically Thank you, 2016 iPhone Don't Make It Work Self-hosted Surveillance with ZoneMinder Backups, Monitoring, and Security for small Mastodon servers Block web scanners with ipset & iptables Executing commands over SSH with GitHub Actions Debian Sid on encrypted ZFS Protect your dangerously insecure redis server Debian: the luxurious boring lifestyle Monitor radiation with a Raspberry Pi Simple Linux server alerts: Know your performance, errors, security, syslog, and security NUC crashes on debian 11 - How I fixed it Basic Linux server security with fail2ban, ossec, and firewall Windows 11 will create heaps of needless trash Domesticated Kubernetes Networking The Cursed Certificate Our mostly disposable and entirely stupid world Trying out OpenBSD (as a Linux geek) Making VoIP Calls with Antique Rotary Phones
Update all your linux servers as fast as possible
2019-09-08 · via Posts on Noah Bailey

Do you ever just update everything?

There’s a few times you might need to do this. For example, some nasty vulnerability comes along and ruins your week.

Or maybe you just want to be super up to date because you have a strange compulsion to have the latest and greatest of everything. Ether way, here’s my solution:

Use Ansible inventories to update all your servers

I wrote this playbook as a simple way to ‘freshen up’ my homelab after months of neglect. In essence, it will apply all available updates for all the hosts in the defined inventory.

After updating each box, it logs all the package updates to a file in the update_logs subdirectory with the date and hostname.

Finally, it will check the if a reboot-required file exists and, as long as the server is a VM, restart it.

Running the script is simple:

ansible-playbook -i inventories/my-environment update.yml 

Try it out:

- name: System Update
  hosts: all
  serial: 10
  tasks: 

  - name: Update packages
    apt: 
      update_cache: yes 
      upgrade: yes
      autoremove: yes 
    register: updates
    become: true 

  - name: Log updated packages 
    copy: 
      content: |
        "{{ updates.stdout }}"        
      dest: "update_logs/{{ ansible_date_time.date }}-{{ inventory_hostname }}.log"
    delegate_to: localhost

  - name: Check pending reboot
    stat: 
      path: /var/run/reboot-required
    register: reboot_required

  - name: Restart server
    reboot: 
      msg: Reload for updates 
      reboot_timeout: 900
    when: reboot_required.stat.exists|bool and (ansible_virtualization_role == 'guest')
    become: true