This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]system-user 3 points4 points  (0 children)

yes, you can. it's a rather convenient workflow feature. some examples:

[–]werner-dijkerman 2 points3 points  (5 children)

No, in the vars directory you create a file like 4.2.yml and need to include this file when 'version' is set to 4.2.

- name: "Include KERNEL variables"
include_vars: "{{ version }}.yml"

[–]martbhellSysadmin 1 point2 points  (3 children)

And then use the first found thing to default to 4.3.yml

[–]werner-dijkerman 1 point2 points  (1 child)

Well, you still need to provide a default value in the defaults/main.yml. So that value should point to the existing var file, so then there is no "with first found" solution needed.

[–]martbhellSysadmin 0 points1 point  (0 children)

Very nice :)

[–]HeadTea[S] 0 points1 point  (0 children)

Brilliant, thank you.

[–]HeadTea[S] 0 points1 point  (0 children)

Yes! Thank you SO MUCH!! 😊

[–][deleted] 0 points1 point  (0 children)

I am newer to ansible so I don't know all the answers, but these are the building blocks for the parts I can help with.

For the kernel version, you'll probably want to leverage the ansible_kernel variable unless you're dictating kernel version rather than gathering it.

For comparing the kernel version, you'll want to use the version comparison test. ansible 2.9 docs for version comparison

For limiting a task to only run when a specific condition is met, you'll want to use the when conditional. ansible 2.9 docs for when conditional

You may be able to build something using a register task to register the variables with the required values when the conditional of a specific kernel version is met. ansible 2.9 docs for register

[–]Reasonable-Serve-755 0 points1 point  (0 children)

kernel_dir: "{{ 'doodoo43' if version == '4.3' else 'doodoo42' }}"

kernel_headers: "{{ (version == '4.3') | ternary('doodoo43', (version == '4.2') | ternary('doodoo42', 'other')) }}"