├── post.sh ├── prepare.sh ├── .tmuxinator.yml ├── Vagrantfile └── ReadMe.md /post.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo ufw allow ansible 4 | -------------------------------------------------------------------------------- /prepare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt-get -y update 4 | sudo apt-get -y install software-properties-common tmux vim 5 | sudo add-apt-repository -y ppa:ansible/ansible 6 | sudo apt-get -y update 7 | -------------------------------------------------------------------------------- /.tmuxinator.yml: -------------------------------------------------------------------------------- 1 | # ~/.tmuxinator/ansible_vagrant.yml 2 | 3 | name: ansible_vagrant 4 | root: ~/ 5 | 6 | # Optional tmux socket 7 | # socket_name: foo 8 | 9 | # Runs before everything. Use it to start daemons etc. 10 | # pre: sudo /etc/rc.d/mysqld start 11 | 12 | # Runs in each window and pane before window/pane specific commands. Useful for setting up interpreter versions. 13 | # pre_window: rbenv shell 2.0.0-p247 14 | 15 | # Pass command line options to tmux. Useful for specifying a different tmux.conf. 16 | # tmux_options: -f ~/.tmux.mac.conf 17 | 18 | # Change the command to call tmux. This can be used by derivatives/wrappers like byobu. 19 | # tmux_command: byobu 20 | 21 | # Specifies (by name or index) which window will be selected on project startup. If not set, the first window is used. 22 | # startup_window: logs 23 | name: ansible_vagrant 24 | project_root: . 25 | 26 | 27 | windows: 28 | - vagrant: 29 | layout: main-vertical 30 | panes: 31 | - vagrant ssh master 32 | - vagrant ssh devops1 33 | - vagrant ssh devops2 34 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.vm.define "master" do |master| 3 | master.vm.box = "hashicorp/precise64" 4 | master.vm.network "private_network", ip: "192.168.100.100" 5 | master.vm.hostname = "master" 6 | master.vm.provision "shell", path: "prepare.sh" 7 | master.vm.provision "shell", inline: "sudo apt-get -y install ansible" 8 | master.vm.provision "shell", inline: "sudo echo '[dev]' >> /etc/ansible/hosts" 9 | master.vm.provision "shell", inline: "sudo echo '192.168.100.101' >> /etc/ansible/hosts" 10 | master.vm.provision "shell", inline: "sudo echo '192.168.100.102' >> /etc/ansible/hosts" 11 | end 12 | 13 | devops_COUNT = 2 14 | 15 | (1..devops_COUNT).each do |devops_id| 16 | config.vm.define "devops#{devops_id}" do |devops| 17 | devops.vm.box = "hashicorp/precise64" 18 | devops.vm.network "private_network", ip: "192.168.100.#{devops_id + 100}" 19 | devops.vm.hostname = "devops#{devops_id}" 20 | devops.vm.provision "shell", path: "prepare.sh" 21 | devops.vm.provision "shell", inline: "sudo apt-get -y install ansible" 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | #Ansible Playground # 2 | 3 | ![tmuxinator ansible-playground](https://s30.postimg.org/ajwn8n0up/ansible-playground.png) 4 | 5 | This is a simple utility repository to bootstrap Ansible playground. It uses VirtualBox and Vagrant to provision: 6 | 7 | * 1 VM to be Master Orchestrator (available at 192.168.100.100) 8 | * n VMs (2 by default) to be DevOps Servers (available at 192.168.100.10[1-9]) 9 | 10 | ###Installation### 11 | 12 | * Install the latest version of [VirtualBox](https://www.virtualbox.org/wiki/Downloads) and VirtualBox extension 13 | * Install [Vagrant](http://www.vagrantup.com/downloads.html) 14 | * Clone this repository: 15 | ``` 16 | $ git clone git@github.com:sureshn/ansible-playground.git 17 | $ cd ansible-playground 18 | ``` 19 | * Start VMs (it will create 3 VMs and provision Ansible). There will also be a hosts file which will be created at /etc/ansible/hosts) which defines a new group named `dev` which contains the DevOps servers. 20 | * Create and provision all VM's: 21 | ``` 22 | $ vagrant up && vagrant provision 23 | ``` 24 | 25 | Once the VM's are up and running, install [tmuxinator](https://github.com/tmuxinator/tmuxinator) and run `mux`. This will connect to the provisioned 3 Vagrant VM's. 26 | 27 | In order for the Master Orchestrator to Communicate with the DevOps Servers, generate a new SSH key in the master shell using `ssh-keygen` and copy the new key to the DevOps machines: 28 | 29 | ``` 30 | vagrant@master:~$ ssh-keygen 31 | ... 32 | vagrant@master:~$ ssh-copy-id vagrant@192.168.100.101 33 | ... 34 | vagrant@master:~$ ssh-copy-id vagrant@192.168.100.102 35 | ... 36 | ``` 37 | 38 | The password for the `vagrant` user on all machines is `vagrant`. 39 | 40 | ###Usage### 41 | 42 | ``` 43 | vagrant@master:~$ ansible dev -a "uptime" 44 | 45 | 192.168.100.101 | success | rc=0 >> 46 | 07:49:11 up 1:22, 2 users, load average: 0.00, 0.01, 0.05 47 | 48 | 192.168.100.102 | success | rc=0 >> 49 | 07:49:11 up 1:19, 2 users, load average: 0.00, 0.01, 0.05 50 | ``` 51 | --------------------------------------------------------------------------------