2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Windows10にAnsibleとTerraformの実行環境をつくる(Vagrantで)

Last updated at Posted at 2019-12-07

Windos10をクライアント端末としてIaCの勉強をしたくなったので
Vagrantで実行環境を作成しました。

環境

Windows10 Pro 1809
Vagrant 2.2.6
VirtualBox 6.0.14
※VMのOSはCentOS7.6、とりあえずgitも入れてる

Vagrantを使用することでwindowsの環境を汚さないでいろいろ実験できます。

Ansible実行環境のVagrantfile

公式ドキュメントのインストール方法
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html

Vagrant.configure('2') do |config|
  config.vm.box = "bento/centos-7.6"
  config.vm.hostname = "ansible.local"
  config.vm.network "private_network",ip: "192.168.33.10"  
  config.vm.define 'ansible' do |host|
  end
  config.vm.provider "virtualbox" do |vb|
    vb.name = "ansible.local"
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end
  config.vm.provider "virtualbox" do |vb|
    config.vm.provision :shell, inline:"sudo yum  install  epel-release -y >/dev/null 2&1"
    config.vm.provision :shell, inline:"sudo yum  install  ansible git -y >/dev/null 2&1"
  end
end

Terraform実行環境のVagrantfile

公式ドキュメント(Terraformは)
https://www.terraform.io/intro/index.html
※wgetとか環境変を入れる実行も自動化したかったが何故か何重にも実行されるのでVM作成後に泣く泣くコマンド投入してます。。。

Terraformを動かすVMを作成

Vagrant.configure('2') do |config|
    config.vm.box = "bento/centos-7.6"
    config.vm.hostname = "terraform.local"
    config.vm.network "private_network",ip: "192.168.33.11"  
    config.vm.define 'terraform' do |host|
    end
    config.vm.provider "virtualbox" do |vb|
      vb.name = "terraform.local"
      vb.customize ["modifyvm", :id, "--memory", "2048"]
      config.vm.provision :shell, :inline:"yum install  wget unzip python3 git -y  >/dev/null 2&1"
  end
end

vagrant up後、OSにログインしてawscliを実行できるようにする(Teraaformを実行する対象はAWSを想定)
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/install-linux.html

# vagrant ssh
[vagrant@terraform ~]$ wget https://bootstrap.pypa.io/get-pip.py
[vagrant@terraform ~]$ python3 get-pip.py --user
[vagrant@terraform ~]$ pip3 install --upgrade --user awscli

Terraformをダウンロードし使えるようにする

[vagrant@terraform ~]$ wget https://releases.hashicorp.com/terraform/0.12.16/terraform_0.12.16_linux_386.zip
[vagrant@terraform ~]$ sudo unzip terraform_0.12.16_linux_386.zip -d /usr/local/bin/

あとはクレデンシャルを環境変数にいれるなりすればAWSに対してTerraformが使用できる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?