- Mac環境
- VirtualBoxはinstall済み
- Vagrantはinstall済み
mkdir cap_test
cd cap_test
vagrant box add "centos_6.6" https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
vagrant init
vi Vagrantfile
Vagrant.configure(2) do |config|
config.vm.define "host" do |node|
node.vm.box = "centos_6.6"
node.vm.hostname = "host"
node.vm.network :private_network, ip: "192.168.43.61"
end
config.vm.define "front1" do |node|
node.vm.box = "centos_6.6"
node.vm.hostname = "front1"
node.vm.network :private_network, ip: "192.168.43.62"
end
end
vagrant up
vagrant status
Set UP Ansible in Host
vagrant ssh host#password is vagrant
su -
wget https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum install -y ansible
Setup ssh
ssh-keygen -t rsa
vi ~/.ssh/config
Host front1 HostName 192.168.43.62
chmod 600 ~/.ssh/config
ssh-copy-id front1これはHostとFrontの両方
sudo yum -y update
Anslbleを使用
Hostvi hosts
[host] 192.168.43.61 [front1] 192.168.43.62ansibleの確認
ansible all -i hosts -m pingmachineのスペックの確認
ansible all -i hosts -m setupパスワード作成: passwordという文字列を暗号化
sa3tHJ3/KuYvI
python -c 'import crypt; print crypt.crypt("password", "salt")'
create japan group and japan user
---
- hosts: all
sudo: yes
tasks:
- name: create japan group
group: name=japan state=present
- name: add a japan user
user: name=japan append=yes group=japan groups=japan,wheel password=sa0l6dugPm7w2
- name: create directory
file: path=/srv/www state=directory owner=japan group=japan mode=0755
- name: install libselinux-python
yum: name=libselinux-python state=latest
- name: install git
yum: name=git state=latest
- name: remove ruby packages
yum: name={{item}} state=absent
with_items:
- ruby
- ruby-augeas
- ruby-libs
- libselinux-ruby
- name: download ruby
get_url: url="ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.0.tar.gz" dest=/usr/local/src
- name: tar
unarchive: src=/usr/local/src/ruby-2.1.0.tar.gz dest=/usr/local/src
- name: configure
command: ./configure --prefix=/usr/local/ruby-2.1.0 --disable-install-rdoc --disable-install-capi chdir=/usr/local/src/ruby-2.1.0
- name: make
command: make chdir=/usr/local/src/ruby-2.1.0
- name: make install
command: make install chdir=/usr/local/src/ruby-2.1.0
- name: change .bashrc for root
lineinfile: dest=/root/.bashrc
line='PATH=$PATH:$HOME/bin:/usr/local/ruby-2.1.0/bin'
backup=yes
state=present
- name: export .bashrc
lineinfile: dest=/root/.bashrc
line='export PATH'
state=present
- name: source .bashrc for root
shell: source /root/.bashrc
- name: change .bashrc for japan
lineinfile: dest=/home/japan/.bashrc
line='PATH=$PATH:$HOME/bin:/usr/local/ruby-2.1.0/bin'
backup=yes
state=present
- name: export .bashrc
lineinfile: dest=/home/japan/.bashrc
line='export PATH'
state=present
- name: source .bashrc for japan
shell: source /home/japan/.bashrc
- name: gem update
shell: /usr/local/ruby-2.1.0/bin/gem update --system
- name: gem install bundle
shell: /usr/local/ruby-2.1.0/bin/gem install bundle
ansible-playbook -v -i hosts playbook_all.yml
vi playbook_host.yml
---
- hosts: front1
sudo: yes
tasks:
- name: install memcached
yum: name=memcached state=present
- name: install ImageMagick packages
yum: name={{item}} state=present
with_items:
- ImageMagick
- ImageMagick-perl
- name: update mysql rpm
yum: name="http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm" state=present
- name: install mysql packages
yum: name={{item}} state=present
with_items:
- mysql
- mysql-server
- mysql-devel
- name: update nginx rpm
yum: name="http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm" state=present
- name: install nginx
yum: name=nginx
- name: install libxml2 packages
yum: name={{item}} state=present
with_items:
- libxml2
- libxml2-devel
- name: install libxslt packages
yum: name={{item}} state=present
with_items:
- libxslt
- libxslt-devel
- name: service mysql nginx memcached
service: name={{item}} state=started enabled=yes
with_items:
- mysqld
- nginx
- memcached
ansible-playbook -v -i hosts playbook_host.yml
Set UP ssh
vagrant ssh host#password is vagrant
su -
visudo変更
#%wheel ALL=(ALL) %wheel ALL=(ALL) ALL
su - japanset id_rsa.pub
vi ~/.ssh/config
Host front1 HostName 192.168.43.62
chmod 600 ~/.ssh/configuser is japan
ssh-copy-id front1ログインを確認
ssh front1
0 件のコメント:
コメントを投稿