Ansible set_fact local and use on remote hosts

I'm trying to get a version on local and use it as a var in other remote hosts

Using the set_fact module in ansible

On local

    - name: Set code version
      shell:  wget -O - -o /dev/null wget -O - -o /dev/null | grep -Po '(?<=<version>)([0-9\.]+(-SNAPSHOT)?)' | sort --version-sort -r| head -n 1
      register: shell_output

    - name: set version
        code_version: "{{ shell_output.stdout }}"
        debug: var=code_version
        run_once: true

On Remote

    - name: test code version
        msg: code version is " {{ code_version }} "

Getting the following error: The task includes an option with an undefined variable. The error was: 'code_version'

If there any way of achieving this??

Read more here:

Content Attribution

This content was originally published by user3292394 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: