Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Allow using a project-specific ansible playbook in *addition* to the …
Browse files Browse the repository at this point in the history
…playbook in the-vagrant.
  • Loading branch information
becw authored Jul 7, 2017
1 parent 772413e commit c116b4a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
9 changes: 8 additions & 1 deletion conf/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ansible_https_enabled = @ansible_https_enabled@
ansible_project_web_root = "@ansible_project_web_root@"
ansible_timezone = "America/Chicago"
ansible_system_packages = []
ansible_custom_playbook = "@ansible_custom_playbook@"
# end tunables

Vagrant.configure(2) do |config|
Expand Down Expand Up @@ -48,7 +49,7 @@ Vagrant.configure(2) do |config|
box.ssh.forward_agent = true
end

config.vm.provision "ansible" do |ansible|
config.vm.provision "the-vagrant", type: "ansible" do |ansible|
ansible.playbook = "@playbook@"

ansible.groups = {
Expand All @@ -66,6 +67,12 @@ Vagrant.configure(2) do |config|
}
end

config.vm.provision "@projectname@-provision", type: "ansible" do |ansible|
if (defined?(ansible_custom_playbook) && !ansible_custom_playbook.empty?)
ansible.playbook = ansible_custom_playbook
end
end

config.trigger.before [:up, :reload] do
run "composer install --ignore-platform-reqs"
end
Expand Down
6 changes: 6 additions & 0 deletions conf/vagrant/provisioning-template/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- hosts: all
vars:
example_var: "This is a stub project-specific playbook."
roles:
- { role: main }
4 changes: 4 additions & 0 deletions conf/vagrant/provisioning-template/roles/main/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Main | Example project-specific role
debug:
msg: "{{ example_var }}"
31 changes: 31 additions & 0 deletions tasks/vagrant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,36 @@
<property name="default.enable_solr" value="Y" />
<property name="default.enable_https" value="n" />
<property name="default.copy_roles" value="n" />
<property name="default.custom_playbook" value="n" />


<!-- Target: install -->
<target name="install" description="Install the vagrantfile and provisioning into your project.">
<!-- Interactive prompts -->
<propertyprompt propertyName="projectname" defaultValue="${default.projectname}" promptText="Enter a short name for your project" promptCharacter=":" useExistingValue="true"/>
<propertyprompt propertyName="project_web_root" defaultValue="${default.project_web_root}" promptText="Web root within your project" promptCharacter=":" useExistingValue="true"/>
<input propertyName="enable_solr" message="Enable Solr " promptChar="?" validArgs="Y,n" defaultValue="${default.enable_solr}" />
<input propertyName="enable_https" message="Enable HTTPS " promptChar="?" validArgs="Y,n" defaultValue="${default.enable_https}" />
<input propertyName="copy_roles" message="Copy Ansible roles into your project for customization " promptChar="?" validArgs="Y,n" defaultValue="${default.copy_roles}" />

<if>
<equals arg1="${copy_roles}" arg2="n"/>
<then>
<input propertyName="custom_playbook" message="OR add an additional Ansible playbook to your project " promptChar="?" validArgs="Y,n" defaultValue="${default.custom_playbook}" />
</then>
<else>
<property name="custom_playbook" value="${default.custom_playbook}" />
</else>
</if>

<!-- Source locations -->
<property name="vagrant.installdir" value="${application.startdir}"/>
<property name="vagrant.ansible.source" value="${phing.dir.vagrant}/../conf/vagrant/provisioning"/>
<property name="vagrant.ansible_template.source" value="${phing.dir.vagrant}/../conf/vagrant/provisioning-template"/>
<property name="vagrant.vagrantfile.source" value="${phing.dir.vagrant}/../conf/vagrant/Vagrantfile"/>
<property name="vagrant.vagrantfile.dest" value="${vagrant.installdir}/Vagrantfile"/>

<!-- Install based on interactive prompt responses above -->
<if>
<equals arg1="${copy_roles}" arg2="Y"/>
<then>
Expand All @@ -41,6 +56,21 @@
</else>
</if>

<if>
<equals arg1="${custom_playbook}" arg2="Y"/>
<then>
<!-- Additional custom playbook -->
<property name="ansible_custom_playbook" value="provisioning/${projectname}.yml" />
<copy todir="${vagrant.installdir}/provisioning">
<fileset dir="${vagrant.ansible_template.source}"/>
</copy>
<move file="${vagrant.installdir}/provisioning/project.yml" tofile="${vagrant.installdir}/provisioning/${projectname}.yml"/>
</then>
<else>
<property name="ansible_custom_playbook" value="" />
</else>
</if>

<if>
<equals arg1="${enable_solr}" arg2="Y"/>
<then>
Expand Down Expand Up @@ -77,6 +107,7 @@
<token key="ansible_solr_enabled" value="${ansible_solr_enabled}"/>
<token key="ansible_https_enabled" value="${ansible_https_enabled}"/>
<token key="ansible_project_web_root" value="${project_web_root}"/>
<token key="ansible_custom_playbook" value="${ansible_custom_playbook}"/>
</replacetokens>
</filterchain>
</copy>
Expand Down

0 comments on commit c116b4a

Please sign in to comment.