Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created March 21, 2018 17:45
Show Gist options
  • Save deekayen/3698782d26be4260abe464bfdd8aef9c to your computer and use it in GitHub Desktop.
Save deekayen/3698782d26be4260abe464bfdd8aef9c to your computer and use it in GitHub Desktop.
Ansible variable substring from regex_replace
---
# RUN: ansible-playbook -i localhost, substr.yml
- hosts: localhost
vars:
stuff: deekayen@WINDOMAIN.COM
ansible_user: deekayen
tasks:
- name: "Crop stuff var into substr var."
set_fact:
substr: "{{ stuff | regex_replace('^(.*?)@WINDOMAIN.COM$', '\\1') }}"
- name: "Return deekayen."
debug:
var: substr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment