大网数据广告活动
服务器运维问答

How to make sure installing updates using apt does not restart networking services?

· 52CE 我爱测

I have an Ansible playbook that I use to configure new Linux VMs. I was recently building a new VM with Ubuntu 22.04. The playbook will write some configuration files related to networking and whatnot, and then the final step of …

问题原文

原帖链接 · Peter Walker · CC BY-SA 4.0

I have an Ansible playbook that I use to configure new Linux VMs. I was recently building a new VM with Ubuntu 22.04. The playbook will write some configuration files related to networking and whatnot, and then the final step of the process is to use Ansibles ansible.builtin.package to install all package updates.

- name: "Install updates"
  become: true
  ansible.builtin.package:
    upgrade: "dist"
  register: res_pkg_updates
  notify: "reboot system"
  tags: [ never, updates ]

My VM was created from a template I made a few months ago, so the Ubuntu OS had a few packages out of date, which isn't unexpected. The problem is that one of the packages must support or provide the networking functionality. So when the package modules starts the VM on the path of installing updates, the networking daemon is restarted, and the VM gets the new IP that was configured earlier in my playbook. This causes the Ansible task to hang, waiting for a reconnection to a machine that is now at a different IP.


I want to know how to configure my ansible.builtin.package task to install package updates but not restart any services, especially networking.

已采纳解答

原帖链接 · John Mahowald · CC BY-SA 4.0

Separate the IP address change from the package transaction and the rest of the play.

First update packages and do whatever other things.

As the last things in this play, update the IP address for this host, but do not bring the interface up on the new IP yet. Maybe by changing a config file. Schedule a reboot of this host a little in the future, such as with ansible.posix.at module. And finally, update DNS so Ansible inventory is aware of the IP change. End of play. Later the host reboots itself, completing the software update and IP change.

A future play can start with a ansible.builtin.wait_for_connection as a convenient way to retry if not up and reachable yet.

ansible.builtin.reboot module in theory can do the reboot, wait for the host to come back, and continue. But it has no good way of rebooting one IP address and come back as another.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2024-01-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。