Skip to content

Instantly share code, notes, and snippets.

@kknd22
Forked from garethrees/Vagrantfile
Last active April 27, 2018 18:09
Show Gist options
  • Save kknd22/125484cbcffdf2e464f484b1a41cb1b4 to your computer and use it in GitHub Desktop.
Save kknd22/125484cbcffdf2e464f484b1a41cb1b4 to your computer and use it in GitHub Desktop.
Example Ansible Delegation
[web]
192.168.33.21
[db]
192.168.33.22
- hosts: web
tasks:
- name: Touch a file on the web server
shell: "echo 'webserver1' > /opt/whoami"
- hosts: db
tasks:
- name: Touch a file on the db server
shell: "echo 'dbserver1' > /opt/whoami"
- hosts: web
tasks:
- name: Collect database server name
register: dbserver_whoami
shell: cat /opt/whoami
delegate_to: "{{ groups['db'][0] }}"
ignore_errors: True
- name: Store database server name
shell: "echo '{{ dbserver_whoami.stdout }}' > /opt/dbserver"
- hosts: db
tasks:
- name: Collect webserver server name
register: webserver_whoami
shell: cat /opt/whoami
delegate_to: "{{ groups['web'][0] }}"
ignore_errors: True
- name: Store webserver server name
shell: "echo '{{ webserver_whoami.stdout }}' > /opt/webserver"
# prepare and install for ssh cert
#
# ssh-keygen -t rsa -C"web"
# ssh-keygen -t rsa -C"db"
#
# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
#
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# sudo rpm -ivh epel-release-6-8.noarch.rpm
# yum --disablerepo=epel -y update ca-certificates
# yum repolist
ansible-playbook ./playbook.yml -i inventory.ini \
-u vagrant -s --private-key=~/.ssh/id_rsa
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'centos6'
config.vm.box_url = 'http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130731.box'
config.vm.boot_timeout = 60
config.vm.define 'web' do |config|
config.vm.network :private_network, ip: '192.168.33.21'
end
config.vm.define 'db' do |config|
config.vm.network :private_network, ip: '192.168.33.22'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment