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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
量子位
T
Tailwind CSS Blog
Vercel News
Vercel News
I
InfoQ
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
Engineering at Meta
Engineering at Meta
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
D
Docker
博客园_首页
P
Proofpoint News Feed
月光博客
月光博客
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Martin Fowler
Martin Fowler
腾讯CDC
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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