Skip to content

Instantly share code, notes, and snippets.

@VireshDoshi
Created February 18, 2018 21:44
Show Gist options
  • Save VireshDoshi/ddc79690626043cf0def7d38f4d6ebbd to your computer and use it in GitHub Desktop.
Save VireshDoshi/ddc79690626043cf0def7d38f4d6ebbd to your computer and use it in GitHub Desktop.
[vdo023@localhost modify_list]$ ansible-playbook -i "localhost," ./modify_list-playbook.yml
PLAY [localhost] **********************************************************************************************************************************
TASK [modify the list values by appending to the end with _changed] *******************************************************************************
ok: [localhost] => {
"msg": "before value: [u'listitem_1', u'listitem_2'] after value: [u'listitem_1_changed', u'listitem_2_changed']"
}
TASK [modify the list values by appending to the end with .changed] *******************************************************************************
ok: [localhost] => {
"msg": "before value: [u'listitem_1', u'listitem_2'] after value: [u'listitem_1.changed', u'listitem_2.changed']"
}
TASK [modify the database value by adding _stg to the first word upto the first dot] **************************************************************
ok: [localhost] => {
"msg": "before value: test.server.net after value: test_stg"
}
TASK [replace the server address dot values with forward slashes] *********************************************************************************
ok: [localhost] => {
"msg": "before value: com.test.application:great:1.0:tar after value: com/test/application/great"
}
PLAY RECAP ****************************************************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0
---
- hosts: localhost
connection: local
gather_facts: False
vars:
my_list:
- listitem_1
- listitem_2
my_database: test.server.net
my_manifest: "com.test.application:great:1.0:tar"
tasks:
- name: modify the list values by appending to the end with _changed
debug:
msg: "before value: {{ my_list }} after value: {{ my_list | map('regex_replace', '(.*)', '\\1_changed') | list }}"
- name: modify the list values by appending to the end with .changed
debug:
msg: "before value: {{ my_list }} after value: {{ my_list | map('regex_replace', '^(.*)$', '\\1.changed') | list }}"
- name: modify the database value by adding _stg to the first word upto the first dot
debug:
msg: "before value: {{ my_database }} after value: {{ my_database | regex_replace('([^\\.]*)\\.(.+)$', '\\1') }}_stg"
- name: replace the server address dot values with forward slashes
debug:
msg: "before value: {{ my_manifest }} after value: {{ my_manifest.split(':')[0] | regex_replace('[.]','/') }}/{{ my_manifest.split(':')[1] }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment