Skip to content

Commit f401525

Browse files
committed
Allow drush alias templates to be overridden
1 parent 8f00a4c commit f401525

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

default.config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ drupalvm_cron_jobs: []
9696
# Drupal VM automatically creates a drush alias file in your ~/.drush folder if
9797
# this variable is 'true'.
9898
configure_drush_aliases: true
99+
drush_aliases_host_template: "templates/drupalvm.aliases.drushrc.php.j2"
100+
drush_aliases_guest_template: "templates/drupalvm-local.aliases.drushrc.php.j2"
99101

100102
# Helper variable to configure the PHP-FPM connection for each Apache
101103
# VirtualHost in the `apache_vhosts` list.

docs/extras/drush.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ $ drush @drupalvm.dev status
3535

3636
Drupal VM automatically generates a drush alias file in `~/.drush/drupalvm.aliases.drushrc.php` with an alias for every site you have defined in the `apache_vhosts` variable.
3737

38+
If you want to customize the generated alias file you can override the `drush_aliases_host_template` and `drush_aliases_guest_template` variables in your `config.yml`.
39+
40+
```yaml
41+
drush_aliases_host_template: "{{ config_dir }}/templates/drupalvm.aliases.drushrc.php.j2"
42+
```
43+
44+
Eg. to only print the alias for your main domain, and not the subdomain you can override the file using a child template.
45+
46+
```php
47+
{% extends 'templates/drupalvm.aliases.drushrc.php.j2' %}
48+
49+
{% block aliases %}
50+
{{ alias('drupalvm.dev', drupal_core_path) }}
51+
{% endblock %}
52+
```
53+
3854
You can disable Drupal VM's automatic Drush alias file management if you want to manage drush aliases on your own. Just set the `configure_drush_aliases` variable in `config.yml` to `false`.
3955

4056
## Using sql-sync

provisioning/tasks/drush-aliases.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Note that this doesn't work for Windows, since Ansible's running in the VM.
1919
- name: Configure host machine drush aliases.
2020
template:
21-
src: ../templates/drupalvm.aliases.drushrc.php.j2
21+
src: "{{ drush_aliases_host_template }}"
2222
dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
2323
delegate_to: 127.0.0.1
2424
become: no
@@ -30,7 +30,7 @@
3030

3131
- name: Configure drush aliases for vagrant user inside VM.
3232
template:
33-
src: ../templates/drupalvm-local.aliases.drushrc.php.j2
33+
src: "{{ drush_aliases_guest_template }}"
3434
dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
3535
become: no
3636
when: configure_drush_aliases
@@ -40,6 +40,6 @@
4040

4141
- name: Configure drush aliases for root user inside VM.
4242
template:
43-
src: ../templates/drupalvm-local.aliases.drushrc.php.j2
43+
src: "{{ drush_aliases_guest_template }}"
4444
dest: "~/.drush/{{ vagrant_machine_name }}.aliases.drushrc.php"
4545
when: configure_drush_aliases

provisioning/templates/drupalvm-local.aliases.drushrc.php.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $aliases['{{ host }}'] = array(
1616
{% endif -%}
1717
{% endmacro %}
1818

19+
{% block aliases -%}
1920
{%- if drupalvm_webserver == 'apache' -%}
2021
{%- for vhost in apache_vhosts -%}
2122
{{ alias(vhost.servername, vhost.documentroot) }}
@@ -32,3 +33,4 @@ $aliases['{{ host }}'] = array(
3233
{%- endfor -%}
3334
{%- endfor -%}
3435
{%- endif -%}
36+
{% endblock %}

provisioning/templates/drupalvm.aliases.drushrc.php.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ $aliases['{{ host }}'] = array(
2222
{% endif -%}
2323
{% endmacro %}
2424

25+
{% block aliases -%}
2526
{%- if drupalvm_webserver == 'apache' -%}
2627
{%- for vhost in apache_vhosts -%}
2728
{{ alias(vhost.servername, vhost.documentroot) }}
@@ -38,3 +39,4 @@ $aliases['{{ host }}'] = array(
3839
{%- endfor -%}
3940
{%- endfor -%}
4041
{%- endif -%}
42+
{% endblock %}

0 commit comments

Comments
 (0)