CentOS7で利用するVagrantFileのまとめ
CentoOS環境で利用するVagrantFileを整理しておく。
VagrantFileは以下の通り。
$ cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core)VagrantFileは以下の通り。
virtualenvインストール用shell $virtualenv = <<SHELL if ! type /usr/local/bin/virtualenv > /dev/null 2 > &1; then # echo $PATHは以下の結果となり、/usr/local/binは含まれていない。 # /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin yum update yum install -y python3 pip3 install virtualenv # vagrantユーザとしてvirtualenvとansibleをインストール su -c "source /vagrant/provision/bash/install_ansible.sh" vagrant # vagrantユーザとしてaws apiをインストール su -c "source /vagrant/provision/bash/install_awsapi.sh" vagrant fi SHELL Vagrant.configure("2") do |config| config.vm.box = "bento/centos-7" config.vm.box_version = "202006.16.0" config.vm.network "private_network", ip: "192.168.33.10" config.vm.provider "virtualbox" do |vm| # vm name vm.name = "ansible-aws" # メモリを設定 vm.memory = 8184 # imageのリソースシェアをON vm.linked_clone = true vm.customize [ "modifyvm", :id, "--cpus", "4", "--ioapic", "on"] config.vbguest.auto_update = true end # 将来ansibleを利用する想定でvaultのためにパーミッションを指定 # Windows版 # config.vm.synced_folder "./provision", "/provision", type:"nfs" # Linux版 config.vm.synced_folder "./provision", "/provision", id: "ansible", owner: "vagrant", group: "vagrant", mount_options: ["dmode=775,fmode=664"] # virtualenvをインストール config.vm.provision "shell", inline: $virtualenv # ansibleを実行
config.vm.provision "shell", inline: <<-SHELL
# ローケールインストール yum reinstall -y glibc glibc-common # timezoneを日本に変更
timedatectl set-timezone Asia/Tokyo
# localeを日本に変更
localectl set-locale LANG=ja_JP.UTF-8
yum reinstall -y glibc glibc-common yum install -y vim # 自分好みのvimrcをshareフォルダに置いておく。 cp /home/vagrant/share/vimrc /home/vagrant/.vimrc cp /home/vagrant/share/vimrc /root/.vimrc chown vagrant:vagrant /home/vagrant/.vimrc SHELL end -shell>
AWSのインストールスクリプトは以下の通り。
/vagrant/provision/bash/install_awsapi.sh
#!/bin/bash yum -y install unzip curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install echo "export PATH=$PATH" >> ~/.bashrc source ~/.bashrc aws --version
AWSの設定は以下の通り。
/vagrant/provision/bash/set_aws_param.txt
#!/bin/bash aws configure set aws_access_key_id default_access_key aws configure set aws_secret_access_key default_secret_key aws configure set default.region ap-northeast-1 aws configure set default.ca_bundle /path/to/ca-bundle.pem aws configure set region us-west-1 --profile testing aws configure set profile.testing2.region eu-west-1
参考
コメント
コメントを投稿