Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Ansible how can I replace a variable with Jinja2

Tags:

ansible

jinja2

I need to replace a variable that has the extra argument passed to it via CLI.

./deploy.yml -e 'jira_ticket=REL-78'

I can't get it to strip out 'deploylist/REL-78' because I'm passing in 'jira_ticket' If i hardcode the varible ('REL-78') it works perfectly.

- name: Set fact
  set_fact: deploy_list"{{ item | replace('deploylist/{{ jira_ticket }}/', '')"
  with_items: ' {{ modules_to_deploy.value }}'
  register: deploy_list_result

ok: [127.0.0.1] => (item=deploylist/REL-78/api)
ok: [127.0.0.1] => (item=deploylist/REL-78/ariaapi)
ok: [127.0.0.1] => (item=deploylist/REL-78/ariaquery)
ok: [127.0.0.1] => (item=deploylist/REL-78/ariaserver)
ok: [127.0.0.1] => (item=deploylist/REL-78/dashboardidp)
ok: [127.0.0.1] => (item=deploylist/REL-78/oracle)
ok: [127.0.0.1] => (item=deploylist/REL-78/uisp)
ok: [127.0.0.1] => (item=deploylist/REL-78/ui)
like image 463
sdot257 Avatar asked Aug 21 '15 18:08

sdot257


1 Answers

How about this... (I also added = and closing }})

- name: Set fact
  set_fact: deploy_list="{{ item | replace('deploylist/'+jira_ticket+'/', '') }}"
  with_items: modules_to_deploy.value
  register: deploy_list_result

Note that you don't have to stringify an argument for with_items.

like image 184
yaegashi Avatar answered Oct 11 '22 14:10

yaegashi