can we fetch a regex match from a variable value

112 views
Skip to first unread message

Max

unread,
Jun 2, 2015, 3:23:04 AM6/2/15
to ansible...@googlegroups.com
Suppose I've url=http://example.com:90/url and now in my ansible task I want to get the url variable by {{ url }} and then do a regex match and fetch oly the hostname i.e. example.com.
Any directions on how this can be achieved would help.

Шалыгин Константин

unread,
Jun 2, 2015, 4:22:14 AM6/2/15
to ansible...@googlegroups.com
- name: Debug
  debug
: msg='facter_fqdn is  {{ facter_fqdn }}'
 
register: 'debug_result'
- name: Fail
  fail
: msg='Sample warning when fqnd != fqdn'
 
when: facter_fqdn.find == "{{ facter_fqdn }}"
- name: Fail
  fail
: msg='Sample warning when fqdn %like% example.com'
 
when: facter_fqdn.find('example.com') != -1
- name: Fail
  fail
: msg='Sample warning when fqdn %like% localdomain'
 
when: facter_fqdn.find('.local') != -1

Max

unread,
Jun 2, 2015, 4:27:23 AM6/2/15
to ansible...@googlegroups.com
Thanks for the response.
The goal is to match a regular expression and then use the value matched for doing other things. Just testing whether a particular string is present or not doesn't suffice for me.
My script should fetch me the host name by using a regex from any of the urls in the format specified above.

Шалыгин Константин

unread,
Jun 2, 2015, 4:37:47 AM6/2/15
to ansible...@googlegroups.com
Read down of page.
Reply all
Reply to author
Forward
0 new messages