LoginSignup
0
0

More than 1 year has passed since last update.

ChatGPTにVagrantfileの記述を手伝ってもらいました

Posted at

概要

最近、Vagratで仮想マシンを立ち上げる機会があったので、流行りのChatGPTにVagrantfileの記述を手伝ってもらいました。

使用するプロバイダはLibvirt、OSをAlmaLInuxにして、CPUを4個、メモリを4GBの仮想マシンを作るためのVagrantfileを作るようにお願いしました。

1回目

はじめ下のスクショの通りに質問をしたら、指定していないネットワークの設定やSSHの設定もありましたが、それらしい答えが返ってきました。しかも仮想マシンを起動するコマンドについても教えてくれました。

Screenshot from 2023-03-18 14-22-59.png

1回目の回答の実行

1回目の回答のVagrantfileをそのままコピペしてきて実行してみました。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.define "almalinux"  # 仮想マシンの名前を指定

  # Vagrant Boxの設定
  config.vm.box = "almalinux/8"
  config.vm.box_version = "8.5.0"
  config.vm.box_check_update = false  # ボックスのアップデートをチェックしない

  # プロバイダの設定
  config.vm.provider :libvirt do |libvirt|
    libvirt.memory = 4096
    libvirt.cpus = 4
  end

  # ネットワークの設定
  config.vm.network :private_network, ip: "192.168.33.10"

  # SSHの設定
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provision "shell", inline: <<-SHELL
    sudo sed -i "s/^PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
    sudo systemctl restart sshd.service
  SHELL
end

結果はあえなく撃沈しました。存在しないバージョンを指定してしまっているみたいです。

$ vagrant up --provider libvirt
Bringing machine 'almalinux' up with 'libvirt' provider...
==> almalinux: Box 'almalinux/8' could not be found. Attempting to find and install...
    almalinux: Box Provider: libvirt
    almalinux: Box Version: 8.5.0
==> almalinux: Loading metadata for box 'almalinux/8'
    almalinux: URL: https://vagrantcloud.com/almalinux/8
The box you're attempting to add has no available version that
matches the constraints you requested. Please double-check your
settings. Also verify that if you specified version constraints,
that the provider you wish to use is available for these constraints.

Box: almalinux/8
Address: https://vagrantcloud.com/almalinux/8
Constraints: 8.5.0
Available versions: 8.3.20210203, 8.3.20210222, 8.3.20210330, 8.3.20210427, 8.4.20210527, 8.4.20210724, 8.4.20211014, 8.5.20211111, 8.5.20211118, 8.5.20211208, 8.5.20220316, 8.6.20220513, 8.6.20220715, 8.6.20220802, 8.6.20220819, 8.6.20220830, 8.6.20221001, 8.7.20221112, 8.7.20230228

2回目

1回目の結果を受けてalmalinuxの最新のバージョンである9.1にしてくださいと指定してみました。今度はalmalinux/9と指定されています。

Screenshot from 2023-03-18 14-33-06.png

2回目の回答の結果

前回と同様に、2回目の回答のVagrantfileをそのままコピペしてきて実行してみました。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.define "almalinux"

  config.vm.box = "almalinux/9"
  config.vm.box_version = "9.1.0"
  config.vm.box_check_update = false

  config.vm.provider :libvirt do |libvirt|
    libvirt.memory = 4096
    libvirt.cpus = 4
  end

  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provision "shell", inline: <<-SHELL
    sudo sed -i "s/^PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
    sudo systemctl restart sshd.service
  SHELL
end

今回も前回と同様なエラーで撃沈しました。よく見るとboxではなくbox_versionの指定してバージョンが存在しないと言われているようなので、box_versionの指定がいらないとChatGPTにお願いしました。

$ vagrant up --provider libvirt
Bringing machine 'almalinux' up with 'libvirt' provider...
==> almalinux: Box 'almalinux/9' could not be found. Attempting to find and install...
    almalinux: Box Provider: libvirt
    almalinux: Box Version: 9.1.0
==> almalinux: Loading metadata for box 'almalinux/9'
    almalinux: URL: https://vagrantcloud.com/almalinux/9
The box you're attempting to add has no available version that
matches the constraints you requested. Please double-check your
settings. Also verify that if you specified version constraints,
that the provider you wish to use is available for these constraints.

Box: almalinux/9
Address: https://vagrantcloud.com/almalinux/9
Constraints: 9.1.0
Available versions: 9.0.20220513, 9.0.20220531, 9.0.20220715, 9.0.20220802, 9.0.20220823, 9.0.20220830, 9.0.20221003, 9.0.20221102, 9.1.20221117

3回目

box_versionの指定がいらないとChatGPTにお願いしたら、このようになりました。

Screenshot from 2023-03-18 14-39-27.png

3回目の回答の結果

また、Vagrantfileをコピペしてきて実行しました。

Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.define "almalinux"

  config.vm.box = "almalinux/9"
  config.vm.box_check_update = false

  config.vm.provider :libvirt do |libvirt|
    libvirt.memory = 4096
    libvirt.cpus = 4
  end

  config.vm.network :private_network, ip: "192.168.33.10"

  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provision "shell", inline: <<-SHELL
    sudo sed -i "s/^PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
    sudo systemctl restart sshd.service
  SHELL
end

今度は起動したみたいです。

$ vagrant up --provider libvirt
Bringing machine 'almalinux' up with 'libvirt' provider...
==> almalinux: Creating image (snapshot of base box volume).
==> almalinux: Creating domain with the following settings...
・
・
==> almalinux: Machine booted and ready!
==> almalinux: Configuring and enabling network interfaces...
==> almalinux: Running provisioner: shell...
    almalinux: Running: inline script

確かに起動しています。

$ vagrant status
Current machine states:

almalinux                 running (libvirt)

感想

確かにほぼ全てChatGPTに書いてもらいましたが、結局Vagrantfileのことのを知っていないとできない修正だったりするので、ある程度のことはVagrantの知識をもっていないとだめなようでした。今回は直接プログラミングではないですが、プログラミングも同じように、補助的な使い方になるのかなという感想です。もしかしたらもっとうまく指示してあげれば良いものを出力してくれるのかもしれません。もっとうまく使いこなせるように、試していきたいと思います。

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