-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #678 from roots/xdebug-alt
Separate Xdebug install/config into separate role, manage SSH Tunnels to remote hosts for debugging
- Loading branch information
Showing
14 changed files
with
223 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env bash | ||
|
||
show_usage() { | ||
echo " | ||
Usage: bin/xdebug-tunnel.sh <action> <host> | ||
<action> can be 'open' or 'close' | ||
<host> is the hostname, IP, or inventory alias in your \`hosts/<environment>\` file. | ||
Examples: | ||
To open a tunnel: | ||
bin/xdebug-tunnel.sh open 12.34.56.78 | ||
To close a tunnel: | ||
bin/xdebug-tunnel.sh close 12.34.56.78 | ||
" | ||
} | ||
|
||
if [[ $1 == "open" ]]; then | ||
REMOTE_ENABLE=1 | ||
elif [[ $1 == "close" ]]; then | ||
REMOTE_ENABLE=0 | ||
else | ||
>&2 echo "The provided <action> argument '${1}' is not acceptable." | ||
show_usage | ||
exit 1 | ||
fi | ||
|
||
if [[ -z $2 ]]; then | ||
>&2 echo "The <host> argument is required." | ||
show_usage | ||
exit 1 | ||
fi | ||
|
||
XDEBUG_ENABLE="-e xdebug_remote_enable=${REMOTE_ENABLE}" | ||
SSH_HOST="-e xdebug_tunnel_inventory_host=$2" | ||
|
||
if [[ -n $DEBUG ]]; then | ||
PARAMS="$PARAMS ${VERBOSITY:--vvvv}" | ||
fi | ||
|
||
ansible-playbook xdebug-tunnel.yml $XDEBUG_ENABLE $SSH_HOST $PARAMS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
xdebug_tunnel_remote_port: 9000 | ||
xdebug_tunnel_host: localhost | ||
xdebug_tunnel_local_port: 9000 | ||
xdebug_tunnel_control_socket: /tmp/trellis-xdebug-{{ xdebug_tunnel_inventory_host }} | ||
xdebug_tunnel_control_identity: "{{ ansible_user_id }}" | ||
|
||
xdebug_tunnel_port_mapping: "{{ xdebug_tunnel_remote_port }}:{{ xdebug_tunnel_host }}:{{ xdebug_tunnel_local_port }}" | ||
xdebug_tunnel_ssh_user: "{{ hostvars[xdebug_tunnel_inventory_host]['ansible_user'] | default(admin_user) }}" | ||
xdebug_tunnel_ssh_host: "{{ hostvars[xdebug_tunnel_inventory_host]['ansible_host'] | default(xdebug_tunnel_inventory_host) }}" | ||
xdebug_tunnel_user_at_host: "{{ xdebug_tunnel_ssh_user }}@{{ xdebug_tunnel_ssh_host }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
- name: Create or close Xdebug SSH tunnel | ||
command: | | ||
{% if xdebug_remote_enable | bool %} | ||
ssh -M -S '{{ xdebug_tunnel_control_socket }}' -fnNT -R {{ xdebug_tunnel_port_mapping }} {{ xdebug_tunnel_user_at_host}} '{{ xdebug_tunnel_control_identity }}' | ||
{% else %} | ||
ssh -S '{{ xdebug_tunnel_control_socket }}' -O exit '{{ xdebug_tunnel_control_identity }}' | ||
{% endif %} | ||
connection: local | ||
register: xdebug_tunnel | ||
ignore_errors: true | ||
|
||
- name: Interpret and present Xdebug SSH tunnel errors | ||
fail: | ||
msg: | | ||
{% if 'already' in xdebug_tunnel.stderr | default('') %} | ||
SSH tunnel already exists! Refer to TODO for help. | ||
{% elif 'No such file or directory' in xdebug_tunnel.stderr | default('') %} | ||
SSH tunnel already closed! | ||
{% endif %} | ||
{{ xdebug_tunnel.stderr | default('Unknown error in handling Xdebug SSH tunnel') }} | ||
when: xdebug_tunnel | failed or 'already' in xdebug_tunnel.stderr | default('') | ||
|
||
- name: Announce Xdebug SSH tunnel status | ||
debug: | ||
msg: SSH Tunnel was {{ xdebug_remote_enable | bool | ternary('created', 'closed') }}! | ||
when: xdebug_tunnel | changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# XDebug Remote Debugging | ||
xdebug_remote_enable: 0 | ||
xdebug_remote_connect_back: 0 | ||
xdebug_remote_host: localhost | ||
xdebug_remote_port: 9000 | ||
xdebug_remote_log: /tmp/xdebug.log | ||
xdebug_idekey: XDEBUG | ||
xdebug_extended_info: 1 | ||
xdebug_max_nesting_level: 200 | ||
|
||
# XDebug Display Settings | ||
xdebug_force_display_errors: 0 | ||
xdebug_force_error_reporting: 0 | ||
xdebug_scream: 0 | ||
xdebug_var_display_max_children: 128 | ||
xdebug_var_display_max_data: 512 | ||
xdebug_var_display_max_depth: 3 | ||
|
||
# XDebug Function/Stack Traces | ||
xdebug_collect_assignments: 0 | ||
xdebug_collect_includes: 1 | ||
xdebug_collect_params: 0 | ||
xdebug_collect_return: 0 | ||
xdebug_collect_vars: 0 | ||
xdebug_show_exception_trace: 0 | ||
xdebug_show_local_vars: 0 | ||
xdebug_show_mem_delta: 0 | ||
xdebug_trace_enable_trigger: 0 | ||
xdebug_trace_enable_trigger_value: | ||
xdebug_trace_format: 0 | ||
xdebug_trace_options: 0 | ||
xdebug_trace_output_dir: /tmp | ||
xdebug_trace_output_name: trace.%c | ||
|
||
# XDebug Profiler | ||
xdebug_profiler_append: 0 | ||
xdebug_profiler_enable: 0 | ||
xdebug_profiler_enable_trigger: 0 | ||
xdebug_profiler_enable_trigger_value: | ||
xdebug_profiler_output_dir: /tmp | ||
xdebug_profiler_output_name: cachegrind.out.%p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
- block: | ||
- name: Install Xdebug | ||
apt: | ||
name: php-xdebug | ||
state: latest | ||
|
||
- name: Template the Xdebug configuration file | ||
template: | ||
src: xdebug.ini.j2 | ||
dest: /etc/php/7.0/mods-available/xdebug.ini | ||
notify: reload php-fpm | ||
|
||
- name: Ensure 20-xdebug.ini is present | ||
file: | ||
src: /etc/php/7.0/mods-available/xdebug.ini | ||
dest: /etc/php/7.0/fpm/conf.d/20-xdebug.ini | ||
state: link | ||
notify: reload php-fpm | ||
|
||
when: xdebug_remote_enable | bool | ||
|
||
- name: Disable Xdebug | ||
file: | ||
path: /etc/php/7.0/fpm/conf.d/20-xdebug.ini | ||
state: absent | ||
when: not xdebug_remote_enable | bool | ||
notify: reload php-fpm | ||
|
||
- name: Disable Xdebug CLI | ||
file: | ||
path: /etc/php/7.0/cli/conf.d/20-xdebug.ini | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
; {{ ansible_managed }} | ||
|
||
[XDebug] | ||
zend_extension=xdebug.so | ||
|
||
; Remote Debugging | ||
xdebug.remote_enable={{ xdebug_remote_enable }} | ||
xdebug.remote_connect_back={{ xdebug_remote_connect_back }} | ||
xdebug.remote_host={{ xdebug_remote_host }} | ||
xdebug.remote_port={{ xdebug_remote_port }} | ||
xdebug.remote_handler=dbgp | ||
xdebug.remote_log={{ xdebug_remote_log }} | ||
xdebug.idekey={{ xdebug_idekey }} | ||
xdebug.extended_info={{ xdebug_extended_info }} | ||
xdebug.max_nesting_level={{ xdebug_max_nesting_level }} | ||
|
||
; Display Settings | ||
xdebug.force_display_errors={{ xdebug_force_display_errors }} | ||
xdebug.force_error_reporting={{ xdebug_force_error_reporting }} | ||
xdebug.scream={{ xdebug_scream }} | ||
xdebug.var_display_max_children={{ xdebug_var_display_max_children }} | ||
xdebug.var_display_max_data={{ xdebug_var_display_max_data }} | ||
xdebug.var_display_max_depth={{ xdebug_var_display_max_depth }} | ||
|
||
; Function/Stack Traces | ||
xdebug.collect_assignments={{ xdebug_collect_assignments }} | ||
xdebug.collect_includes={{ xdebug_collect_includes }} | ||
xdebug.collect_params={{ xdebug_collect_params }} | ||
xdebug.collect_return={{ xdebug_collect_return }} | ||
xdebug.collect_vars={{ xdebug_collect_vars }} | ||
xdebug.show_exception_trace={{ xdebug_show_exception_trace }} | ||
xdebug.show_local_vars={{ xdebug_show_local_vars }} | ||
xdebug.show_mem_delta={{ xdebug_show_mem_delta }} | ||
xdebug.trace_enable_trigger={{ xdebug_trace_enable_trigger }} | ||
xdebug.trace_enable_trigger_value={{ xdebug_trace_enable_trigger_value }} | ||
xdebug.trace_format={{ xdebug_trace_format }} | ||
xdebug.trace_options={{ xdebug_trace_options }} | ||
xdebug.trace_output_dir={{ xdebug_trace_output_dir }} | ||
xdebug.trace_output_name={{ xdebug_trace_output_name }} | ||
|
||
; Profiler | ||
xdebug.profiler_append={{ xdebug_profiler_append }} | ||
xdebug.profiler_enable={{ xdebug_profiler_enable }} | ||
xdebug.profiler_enable_trigger={{ xdebug_profiler_enable_trigger }} | ||
xdebug.profiler_enable_trigger_value={{ xdebug_profiler_enable_trigger_value }} | ||
xdebug.profiler_output_dir={{ xdebug_profiler_output_dir }} | ||
xdebug.profiler_output_name={{ xdebug_profiler_output_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- name: Determine Remote User | ||
hosts: "{{ xdebug_tunnel_inventory_host }}" | ||
gather_facts: false | ||
roles: | ||
- { role: remote-user, tags: [remote-user, always] } | ||
|
||
- name: Enable or Disable Xdebug and SSH Tunnel | ||
hosts: "{{ xdebug_tunnel_inventory_host }}" | ||
roles: | ||
- { role: xdebug, tags: [xdebug] } | ||
- { role: xdebug-tunnel, tags: [xdebug-tunnel] } | ||
handlers: | ||
- name: reload php-fpm | ||
service: | ||
name: php7.0-fpm | ||
state: reloaded |