Variables question - construct file name out of 2 facts

51 views
Skip to first unread message

Leibo

unread,
Jun 16, 2014, 4:23:19 AM6/16/14
to ansible...@googlegroups.com
Hi,

Newbie question I suppose...

I have a tasks file inside a role where I want to copy some OS and Arch dependent package - 2 conditionals.

The issue I'm struggling with is to assign the right source file name to the task.

The task:

- name: Copy the relevant pkg to /var/tmp
  copy: src=my_repo/{{ pkg _name }} dest=/var/tmp/

Now per OS/Arch I need to get the right name of the package
I have different packages for Linux x86 and x86_64 for example, same for Solaris sparc and x86...

I created a var/ main.yml file and thought populating it the the correct file name assignment

What's the efficient way to get this ok?


Thanks




James Cammarata

unread,
Jun 16, 2014, 11:49:59 AM6/16/14
to ansible...@googlegroups.com
It sounds like you simply need to specify the system facts as the src name. For example, src=my_repo/{{ansible_system}}/{{ansible_architecture}}/{{pkg_name}}, which would work assuming you have your files organized as:

dir:
  Linux/
    x86/
    x86_64/
  Solaris:
    sparc/
    x86_64/

etc.



--
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 post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e3e74bce-7b99-4574-94c4-fde192d8c17c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leibo

unread,
Jun 16, 2014, 1:56:43 PM6/16/14
to ansible...@googlegroups.com
Hi,

Thanks,

What about the package name, if it is different between OS and Arch?

I managed now to include var files based on Ansible facts as their name, Is there a way to use Ansible facts as var names?
Example:

my_pkg_Linux_x86_64: ''package name''

And use ''my_pkg_{{ ansible_system }}_{{ansible_architecture}}'' as the argument to module in a task?

James Cammarata

unread,
Jun 16, 2014, 2:26:23 PM6/16/14
to ansible...@googlegroups.com
Yes, all ansible facts are variables available to be used.


--
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 post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages