Skip to content

Instantly share code, notes, and snippets.

@tsubakimoto
Created December 2, 2014 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubakimoto/74a667d0080186b3cbd1 to your computer and use it in GitHub Desktop.
Save tsubakimoto/74a667d0080186b3cbd1 to your computer and use it in GitHub Desktop.

vagrant up

vagrant ssh host

cp /vagrant/hosts .

chmod -x hosts

cp /vagrant/ansible.cfg .

vi ~/.ssh/config

Host jenkins
  HostName 192.168.22.11

chmod 600 ~/.ssh/config

ssh-keygen -t rsa

ssh-copy-id jenkins

cp /vagrant/playbook.yml .

ansible-playbook playbook.yml

[defaults]
hostfile = ./hosts
[servers]
192.168.22.11
---
- hosts: servers
sudo: yes
tasks:
- name: wget jenkins repo
get_url: url=http://pkg.jenkins-ci.org/redhat/jenkins.repo dest=/etc/yum.repos.d/jenkins.repo
- name: import rpm key
rpm_key: state=present key=http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
- name: uninstall java
yum: name=java state=absent
- name: install java-1.6.0-openjdk
yum: name=java-1.6.0-openjdk state=present
- name: install jenkins
yum: name=jenkins state=latest
notify: start jenkins
#- name: allow port 8080
# lineinfile: dest=/etc/sysconfig/iptables line="-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT" insertafter="^:OUTPUT "
# notify: restart iptables
handlers:
- name: restart iptables
service: name=iptables state=restarted
- name: start jenkins
service: name=jenkins state=started
#- hosts: all
# sudo: yes
# tasks:
# - name: add a new user
# user: name=tsubaki
# - name: install libselinux-python
# yum: name=libselinux-python state=latest
#
#- hosts: web
# sudo: yes
# tasks:
# - name: install apache
# yum: name=httpd state=latest
# - name: start apache and enabled
# service: name=httpd state=started enabled=yes
# - name: change owner
# file: dest=/var/www/html owner=vagrant recurse=yes
# # - name: copy index.html
# # copy: src=./index.html dest=/var/www/html/index.html owner=vagrant
# - name: install php packages
# yum: name={{item}} state=latest
# with_items:
# - php
# - php-devel
# - php-mbstring
# - php-mysql
# notify:
# - restart apache
# - name: copy hello.php
# copy: src=./hello.php dest=/var/www/html/hello.php owner=vagrant
# handlers:
# - name: restart apache
# service: name=httpd state=restarted
#
#- hosts: db
# sudo: yes
# tasks:
# - name: install mysql
# yum: name={{item}} state=latest
# with_items:
# - mysql-server
# - MySQL-python
# - name: start mysql and enabled
# service: name=mysqld state=started enabled=yes
# - name: create a database
# mysql_db: name=mydb state=present
# - name: create a user for mydb
# mysql_user: name=dbuser password=dbpassword priv=mydb.*:ALL state=present
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
$script = <<SCRIPT
echo Ansible installing...
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
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "host" do |node|
node.vm.box = "chef/centos-6.5"
node.vm.hostname = "host"
node.vm.network :private_network, ip: "192.168.22.10"
node.vm.provision "shell", inline: $script
end
config.vm.define "jenkins" do |node|
node.vm.box = "chef/centos-6.5"
node.vm.hostname = "jenkins"
node.vm.network :private_network, ip: "192.168.22.11"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment