Pre-create list of volumes for docker_container command?

36 views
Skip to first unread message

Koen De Groote

unread,
Aug 28, 2019, 4:08:10 PM8/28/19
to Ansible Project

I'm looking for some help or guidance in trying to create a list of volumes to pass along to docker container, before that actual command.

So, the format for this is:


    volumes:
    - '{{ dir1 }}:{{ dir1 }}'
    - '/tmp:/tmp'


And so on...

But I'm looking at a case where the volumes are dynamic. And I'd like to put them in a variable before this step and then pass that variable along.

The alternative right now is a bunch of separate docker_container steps with a when condition, which is not very efficient.

Dick Visser

unread,
Aug 29, 2019, 12:23:22 AM8/29/19
to ansible...@googlegroups.com
Hi

On Wed, 28 Aug 2019 at 22:08, Koen De Groote <kdg...@gmail.com> wrote:

I'm looking for some help or guidance in trying to create a list of volumes to pass along to docker container, before that actual command.

So, the format for this is:


    volumes:
    - '{{ dir1 }}:{{ dir1 }}'
    - '/tmp:/tmp'


And so on...

But I'm looking at a case where the volumes are dynamic. And I'd like to put them in a variable before this step and then pass that variable along.


Yes that is possible. 
But it’s not clear what the problem is, or what is the question you have with this?
I.E. what exactly are you looking for?

The alternative right now is a bunch of separate docker_container steps with a when condition, which is not very efficient.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0d70b7a7-f0aa-4ee7-b81a-9fe2c1fada85%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Koen De Groote

unread,
Aug 29, 2019, 6:19:48 PM8/29/19
to ansible...@googlegroups.com
The question is: how do you do it? I'm looking for an example.

Nothing I've found so far in the documentation says outright "this is how it's done".

I'm uncertain what kind of variable I need to produce, in what way, so that it is the correct one for this field to accept it.

This may be obvious to a lot of people, but not to me.




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/j8rhJiGQkgI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAL8fbwN8FCLe8gpZgcEQOz_eM%3DhG3ootMvZbZhqJqe-_Et035g%40mail.gmail.com.

Kai Stian Olstad

unread,
Aug 29, 2019, 6:27:08 PM8/29/19
to ansible...@googlegroups.com
On 29.08.2019 22:19, Koen De Groote wrote:
> The question is: how do you do it? I'm looking for an example.
>
> Nothing I've found so far in the documentation says outright "this is how
> it's done".
>
> I'm uncertain what kind of variable I need to produce, in what way, so that
> it is the correct one for this field to accept it.
>
> This may be obvious to a lot of people, but not to me.

You have this

volumes:
- '{{ dir1 }}:{{ dir1 }}'
- '/tmp:/tmp'

The dashes indicates it's a list, and pretty sure if you check the documentation it says that volumes takes a list.
So create a variable with a list in it and provide that variable to volumes.

Define a variable
vars:
myvar:
- '{{ dir1 }}:{{ dir1 }}'
- '/tmp:/tmp'

and then use it

volumes: '{{ myvar }}'

--
Kai Stian Olstad

Koen De Groote

unread,
Sep 9, 2019, 9:50:26 AM9/9/19
to Ansible Project

Apologies for the late reply.

What I'm looking for is more something for use inside a role, and also additive.
So, if I already have a list, to be able to specificy a "when" condition and if the condition is met, add something to the list.
Reply all
Reply to author
Forward
0 new messages