LoginSignup
5
4

More than 5 years have passed since last update.

unattended-upgrades を TUI を使わずに有効化するには (構成管理ツールなど非インタラクティブな状況とか)

Posted at

Debian や Ubuntu で、セキュリティ上重要なアップデートを自動でアップグレードを実施してくれる、
unattended-upgrades というとてもありがたいパッケージがあるのだが、インストールしたそのままでは有効化されない。

インストール後に dpkg-reconfigure で設定を行う必要がある。
すると TUI の画面で入力を求められる。

こんな感じ

$ sudo apt-get install -y unattended-upgrades
$ sudo dpkg-reconfigure -plow unattended-upgrades

このような確認.png

やりたいこと

これを apt-get-y オプションのように、
人による確認をスキップして、コマンドだけで自動で設定することはできないかと思い、調べた。

それができれば、 Chef や Ansible のような構成管理ツールで unattended-upgrades を有効化するのが簡単になる。

答え

$ echo 'unattended-upgrades unattended-upgrades/enable_auto_updates boolean true' \
| sudo debconf-set-selections
$ sudo dpkg-reconfigure -f noninteractive -plow unattended-upgrades

のようにすれば OK だった。
debconf-set-selections 経由で入力でき、 -f noninteractive オプション付きで読み込ませるので TUI が立ち上がらない。

debconf-set-selections というコマンドを使って設定するので、もしデフォルトでインストールされていないディストリを使っているら、 debconf-utils パッケージをインストールする必要がある。
たいていは最初から使えることが多いが、後述の debconf-get-selections コマンドも debconf-utils に含まれているので、インストールしてしまうのがスムーズだと思う。

$ sudo apt-get install -y debconf-utils

キーワードの探し方

ところで、こういった debconf 周りで自動で設定をしたい機会は他にもありそうだ。
unattended-upgrades/enable_auto_updates のようなキーワードをどうやって知ればよいだろうか?

やはり debconf-utils に含まれている debconf-get-selections コマンドを使えば、現在の debconf の設定をすべてテキストで得ることができる。
ここには

{パッケージ名} {パッケージ内の設定項目名} {型} {値}

のような形式で記述されているので、そのままパッケージ名で grep すれば簡単に検索できる。

$ sudo debconf-get-selections | grep unattended-upgrades
unattended-upgrades     unattended-upgrades/enable_auto_updates boolean true
$ 

関連

Debian 系で unattended-upgrades を有効にする場合の追加設定 (メール通知, autoremove, autoclean, 再起動)

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4