Reputation: 437
I have an ansible task:
- name: Copy files from A to B
copy:
src: "{{ item }}"
dst: /usr/lib/modules/$(uname -r)/misc/
with_items:
- file.one
- file.two
The problem is, that ansible creates a directory called /usr/lib/modules/$(uname -r)/misc/ (literally) and copies the files there instead of substituting the $(uname -r)
with the command's output.
How can I get this done?
Upvotes: 0
Views: 364
Reputation: 2916
To add to @joppich's answer, if you want to substitute in a value that is not available as a fact, you can use Registered Variables:
- name: Determine kernel version
command: uname -r
register: r_uname
- name: Copy files from A to B
copy:
src: "{{ item }}"
dst: /usr/lib/modules/{{ r_uname.stdout_lines[0] }}/misc/
with_items:
- file.one
- file.two
Upvotes: 1
Reputation: 681
By default, ansible will run it's setup module and discover facts about the target system.
You can access these facts like any variable:
- name: Copy files from A to B
copy:
src: "{{ item }}"
dst: /usr/lib/modules/{{ ansible_kernel }}/misc/
with_items:
- file.one
- file.two
Upvotes: 4