Search code examples
ansibleansible-inventory

Ansible set_fact wget version


I'm trying to run the set_fact task at the start of my ansible-playbook to set a version and use it in my playbook.

I have tried to this and failing with incorrect syntax, I think

- name: "SO Nightly code build"
  remote_user: root
  hosts: cleanroom
  tasks:
    - name: Set version
      set_fact:
        version: {{wget -O - -o /dev/null https://repo1.maven.org/maven2/org/brutusin/wava/maven-metadata.xml | grep -Po '(?<=<version>)([0-9\.]+(-SNAPSHOT)?)' | sort --version-sort -r| head -n 1}}
      debug var=version

Hoping to get the version so I can pass it through the rest of my playbook


Solution

  • solved it by running the wget as a shell and setting it as the output find code below

        - name: Set code version
          shell:  wget -O - -o /dev/null wget -O - -o /dev/null https://repo1.maven.org/maven2/org/brutusin/wava/maven-metadata.xml | grep -Po '(?<=<version>)([0-9\.]+(-SNAPSHOT)?)' | sort --version-sort -r| head -n 1
          register: shell_output
    
        - name: set version
          set_fact:
            code_version: "{{ shell_output.stdout }}"
            debug: var=code_version