Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Last active May 21, 2019 12:20
Show Gist options
  • Save zeitounator/0725f6006101e28a5edd889f8132632e to your computer and use it in GitHub Desktop.
Save zeitounator/0725f6006101e28a5edd889f8132632e to your computer and use it in GitHub Desktop.
ansible complex string example proof for https://stackoverflow.com/a/56234698/9401096
---
- name: complex string
hosts: localhost
gather_facts: false
vars:
DATABASE_LISTDELETED_RESOURCEGROUP: my_ressource_group
DATABASE_LISTDELETED_SQLSERVER: my_sql_server
DATABASE_LISTDELETED_QUERY: this is a line of text which mimics an actual query I don't have
tasks:
- name: Store my command in a var
set_fact:
my_command: >-
az sql db list-deleted
--resource-group "{{ DATABASE_LISTDELETED_RESOURCEGROUP }}"
--server "{{ DATABASE_LISTDELETED_SQLSERVER }}"
{% if DATABASE_LISTDELETED_QUERY is defined %}
--query "{{ DATABASE_LISTDELETED_QUERY }}"
{% endif %}
--output json
- debug:
var: my_command
PLAY [complex string] **********************************************************
TASK [Store my command in a var] ***********************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"my_command": "az sql db list-deleted --resource-group \"my_ressource_group\" --server \"my_sql_server\" --query \"this is a line of text which mimics an actual query I don't have\" --output json"
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
---
- name: complex string
hosts: localhost
gather_facts: false
vars:
DATABASE_LISTDELETED_RESOURCEGROUP: my_ressource_group
DATABASE_LISTDELETED_SQLSERVER: my_sql_server
tasks:
- name: Store my command in a var
set_fact:
my_command: >-
az sql db list-deleted
--resource-group "{{ DATABASE_LISTDELETED_RESOURCEGROUP }}"
--server "{{ DATABASE_LISTDELETED_SQLSERVER }}"
{% if DATABASE_LISTDELETED_QUERY is defined %}
--query "{{ DATABASE_LISTDELETED_QUERY }}"
{% endif %}
--output json
- debug:
var: my_command
PLAY [complex string] **********************************************************
TASK [Store my command in a var] ***********************************************
ok: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"my_command": "az sql db list-deleted --resource-group \"my_ressource_group\" --server \"my_sql_server\" --output json"
}
PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment