using mutiple times same values

15 views
Skip to first unread message

coach...@gmail.com

unread,
Dec 20, 2017, 6:57:00 AM12/20/17
to Ansible Project
I am trying to create multiple different directory structure using the with_items and again i need to refer the same directory structure in the other plays in the playbook.

for example

- file: name=/jenkins/data/{{item.dir1}}/{{item.dir2}}
  with_items:
     - {dir1: str-build, dir2: gitconfig_dev}
     - {dir1: btr-build, dir2: gitconfig_test}
     - {dir1: ctr-build, dir2: gitconfig_test6}
     ......................................
     there are around 20 items like this
     ......................................
same variable i need to refer in the other play like
- git: repo=http://github/.....   dest=/jenkins/data/{{item1.dir1}}/{{item.dir2}} clone=yes
  with_items:
    - {dir1: str-build, dir2: gitconfig_dev}
    - {dir1: btr-build, dir2: gitconfig_test}
    - {dir1: ctr-build, dir2: gitconfig_test6}

Again in some other play ...so how do i make this global so that we define once with_items and use it in all the other play..
 thank you.

 

Kai Stian Olstad

unread,
Dec 20, 2017, 9:55:23 AM12/20/17
to ansible...@googlegroups.com
> Again in some other play ...so how do i make this* global *so that we
> define once *with_items* and use it in all the other play..
> thank you.

Add it in a variable in group_vars/all.yml then it's global.

all.yml
---
jenkins_dir:
- {dir1: str-build, dir2: gitconfig_dev}
- {dir1: btr-build, dir2: gitconfig_test}
- {dir1: ctr-build, dir2: gitconfig_test6}


They you can use

with_items: '{{ jenkins_dir }}'


--
Kai Stian Olstad

coach rhca

unread,
Dec 20, 2017, 11:01:12 PM12/20/17
to ansible...@googlegroups.com
thanks Kai, i will check this one...thanks a bunch


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/zFD4y6aWdeY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9370214.p3PfHMhOmn%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages