Skip to content

Commit

Permalink
refactor reporting to use post_message, hostname/devDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Jan 15, 2018
1 parent 8184e5a commit 0b51452
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
site/*
node_modules
*.retry
.ip_address
38 changes: 18 additions & 20 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,21 @@ Vagrant.configure(2) do |config|
config.vm.box_version = ">= 1.4.0"
# config.vm.box = "basic-wp"
config.vm.hostname = $hostname
config.vm.define $hostname
config.vm.define $devDomain

config.vm.post_up_message = Proc.new {
ip = File.read(__dir__ + '/.ip_address').strip
protocol = $ansible_config['use_ssl'] ? 'https://' : 'http://'
msg = " Thank you for using Basic WordPress Vagrant (v#{$version})\n"
msg << " https://github.com/ideasonpurpose/basic-wordpress-vagrant\n\n"
msg << " Local server addresses:\n" if Vagrant.has_plugin? 'vagrant-hostmanager'
msg << " #{ protocol }#{ $devDomain }\n" if Vagrant.has_plugin? 'vagrant-hostmanager'
msg << " Local server address:\n" if not Vagrant.has_plugin? 'vagrant-hostmanager'
msg << " #{ protocol }#{ ip }\n"
msg << "-"
msg
}


if Vagrant.has_plugin? 'vagrant-auto_network'
config.vm.network :private_network, auto_network: true, id: "basic-wordpress-vagrant_#{$hostname}"
Expand All @@ -56,7 +70,7 @@ Vagrant.configure(2) do |config|
v.customize ["modifyvm", :id, "--cpus", 1]
v.customize ["modifyvm", :id, "--memory", 512]
v.customize ["modifyvm", :id, "--vram", 4]
v.customize ["modifyvm", :id, "--name", $hostname]
v.customize ["modifyvm", :id, "--name", $devDomain]
v.customize ["modifyvm", :id, "--ioapic", "on"]
v.customize ["modifyvm", :id, "--paravirtprovider", "kvm"]
v.customize ["modifyvm", :id, "--cableconnected1", 'on']
Expand All @@ -77,30 +91,14 @@ Vagrant.configure(2) do |config|
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.aliases = [$devDomain]
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
ip_addr = ""
cmd = "VBoxControl --nologo guestproperty get /VirtualBox/GuestInfo/Net/1/V4/IP | cut -f2 -d' '"
cmd = "VBoxControl --nologo guestproperty get /VirtualBox/GuestInfo/Net/1/V4/IP | cut -f2 -d' '" #" | tee /vagrant/.ip_address"
vm.communicate.sudo(cmd) do |type, data|
ip_addr << data.strip
end
ip_addr
end

server_address = ($ansible_config['use_ssl'] ? 'https://' : 'http://') + $hostname
config.vm.provision "Summary", type: "shell", privileged: false, inline: <<-EOF
echo "Vagrant Box provisioned!"
echo "Basic WordPress Vagrant version: #{$version}"
echo "Local server addresses is #{server_address}"
EOF

else
server_address = $ansible_config['use_ssl'] ? 'https://$IP' : 'http://$IP'
config.vm.provision "Summary", type: "shell", privileged: true, inline: <<-EOF
echo "Basic WordPress Vagrant version: #{$version}"
echo "Vagrant Box provisioned!"
IP=`VBoxControl --nologo guestproperty get /VirtualBox/GuestInfo/Net/1/V4/IP | cut -f2 -d' '`
echo "Local server address is #{server_address}"
EOF

end
end
2 changes: 1 addition & 1 deletion ansible/roles/wordpress/tasks/wp-config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: get VM's IP Address
shell: VBoxControl --nologo guestproperty get /VirtualBox/GuestInfo/Net/1/V4/IP | cut -f2 -d' '
shell: VBoxControl --nologo guestproperty get /VirtualBox/GuestInfo/Net/1/V4/IP | cut -f2 -d' ' | tee /vagrant/.ip_address
register: ip_addr

- set_fact: site_addr={{ site_name or ip_addr.stdout }}
Expand Down

0 comments on commit 0b51452

Please sign in to comment.