1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ansibleを利用してProxmox VEの初期設定を自動化する

1
Last updated at Posted at 2026-02-07

はじめに

Proxmox VE 9(開発版/最新版)は Debian 13 (Trixie) をベースにしており、リポジトリの設定形式も従来の .list 形式から新しい DEB822形式 (.sources) へと移行が進んでいます。

この記事では、Ansibleを用いて以下の「ポストインストール・ルーチン」を自動化する手順を解説します。

  1. リポジトリの正常化: 有料版(Enterprise)の無効化と無料版の有効化
  2. DEB822形式への対応: .sources ファイルによる 401 Unauthorized エラーの解消
  3. サブスクリプション警告の非表示化: ログイン時のポップアップを無効化
  4. システムアップデート: 最新パッケージへの更新

1. Ansibleサーバーの構築

まずは管理側となるAnsibleサーバーを用意します。

Ansibleの導入

前回VMテンプレートから作成したAnsibleサーバにAnsibleを導入します。

# パッケージリストの更新
sudo apt update
# Ansibleのインストール
sudo apt install -y ansible

SSH鍵の生成と配布

パスワードレスでProxmoxを操作できるように設定します。

# 鍵の生成(すべてEnterキーでOK)
ssh-keygen -t ed25519

# Proxmoxサーバーへ鍵をコピー (IPは環境に合わせて変更)
ssh-copy-id root@192.168.11.11


2. Ansibleプロジェクトの作成

作業用ディレクトリを作成し、必要な設定ファイルを準備します。

mkdir pve-management
cd pve-management

インベントリファイル (hosts.ini)

管理対象のIPアドレスを定義します。

[proxmox]
192.168.11.11

設定ファイル (ansible.cfg)

[defaults]
inventory = hosts.ini
remote_user = root
host_key_checking = False

プレイブック (pve_setup.yml)

ここが重要です。PVE 9 特有の .sources ファイルを削除し、適切な無料版リポジトリを再構築します。

---
- name: Proxmox VE 9 Post Install Setup (DEB822 Support)
  hosts: proxmox
  gather_facts: yes

  tasks:
    - name: 標準リポジトリ(Debian 13 Trixie)の設定
      copy:
        dest: /etc/apt/sources.list
        content: |
          deb http://deb.debian.org/debian trixie main contrib
          deb http://deb.debian.org/debian trixie-updates main contrib
          deb http://security.debian.org/debian-security trixie-security main contrib

    - name: 不要な .sources ファイルを削除 (DEB822形式)
      file:
        path: "/etc/apt/sources.list.d/{{ item }}"
        state: absent
      loop:
        - pve-enterprise.sources
        - ceph.sources
        - debian.sources

    - name: PVE 9 無料版リポジトリを有効化 (.list形式)
      copy:
        dest: /etc/apt/sources.list.d/pve-install-repo.list
        content: "deb http://download.proxmox.com/debian/pve trixie pve-no-subscription"

    - name: Ceph 無料版リポジトリを有効化 (.list形式)
      copy:
        dest: /etc/apt/sources.list.d/ceph.list
        content: "deb http://download.proxmox.com/debian/ceph-squid trixie no-subscription"

    - name: APTキャッシュの更新
      apt:
        update_cache: yes

    - name: システムのアップグレード
      apt:
        upgrade: dist
        autoremove: yes

3. 実行

疎通確認

ansible proxmox -m ping

SUCCESS と表示されれば準備完了です。

プレイブックの実行

ansible-playbook pve_setup.yml


解説:なぜ .sources を消すのか?

Proxmox VE 9 (Debian 13) では、従来の一行形式 (.list) ではなく、構造化された DEB822形式 (.sources) が標準採用されています。

インストール直後は /etc/apt/sources.list.d/pve-enterprise.sources が存在しており、これが優先されるため、無料版の設定を追加しても 401 Unauthorized エラーが発生し続けます。本プレイブックではこれを物理的に削除することで、不整合を解消しています。

まとめ

Ansibleを利用することで、PVE 9のような新しい環境でも、一度確立した「正解の設定」を何度でも再現できるようになります。自宅サーバーや検証環境の構築にぜひ役立ててください。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?