Because I would rather use jinja2 than piping through a bunch of shell
commands:
- name: Run java -version
command: java -version
register: java_version_out
changed_when: false
- name: Set java_version var
set_fact: java_version="{{
java_version_out.stderr.splitlines()[0]|regex_replace('[^\d.]+', '') }}"
- debug: var=java_version
On Fri, May 8, 2015 at 4:21 PM, John Oliver <[email protected]> wrote:
> I want to register a variable with my java version. I can get that with:
>
> java -version 2>&1 | head -1 | awk 'BEGIN { FS = "\"" } ; { print $2 }'
>
> That gives me the result I want: 1.8.0_45
>
> But I cannot make this happen in ansible :-( I'm going crazy with quotes
> and escapes. I've tried:
>
> - name: Get java version
> shell: >
> java -version 2>&1 | head -1 | awk 'BEGIN { FS = "\"" } ; { print
> $2 }'
> register: java_ver
>
> and:
>
> - name: Get java version
> command: "{{ item }}"
> with_items:
> - java -version 2>&1 | head -1 | awk 'BEGIN { FS = "\"" } ; { print
> $2 }'
> register: java_ver
>
> as well as trying various combinations of quotes and escape characters. I
> just can't get the right recipe.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/30e7016d-9285-424a-adb7-2fca96e87044%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/30e7016d-9285-424a-adb7-2fca96e87044%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAD8N0v8_o1UNQyWHo5wABkZxU7VG3b-NqtB0gc7gLSopX54XXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.