0

this is my first question here, I am so excited :)

It's maybe a noob question but I don't understand it...

I'am trying to upgrade an Edgerouter firmware (https://www.ui.com/edgemax/edgerouter-pro/) with Gitlab-CI and Ansible. The stages are absolutely identical but the stdout of the same task, with the same ansible.cfg, with the same gitlab-runner, in the same pipeline etc., differs:

STAGE1

CI Deployment Docker Image:
ansible-playbook 2.8.3
python version = 3.7.4

Edgerouter:
USER1@HOSTNAME1:~$ python --version
Python 2.7.13

USER1@HOSTNAME1:~$ show system image
The system currently has the following image(s) installed:

v2.0.8.5247496.191120.1124     (running image) (default boot)
v2.0.8.5247496.191120.1124-1
OUTPUT
...identical verbose output, but:
ok: [HOSTNAME1] => changed=false 
  invocation:
    module_args:
      commands:
      - show version | grep "Build ID"  | cut -d ':' -f 2 | tr -d ' '
      interval: 1
      match: all
      retries: 10
      wait_for: null
  stdout:
  - '5247496'
  stdout_lines: <omitted>

Works like a charm! BUT:

STAGE2

CI Deployment Image:
ansible-playbook 2.8.3
python version = 3.7.4

Edgerouter
USER2@HOSTNAME2:~$ python --version
Python 2.7.13

USER2@HOSTNAME2:~$ show system image
The system currently has the following image(s) installed:

v2.0.8.5247496.191120.1124     (running image) (default boot)
v2.0.8.5247496.191120.1124-1
OUTPUT
...identical verbose output, but:
ok: [HOSTNAME2] => changed=false 
  invocation:
    module_args:
      commands:
      - show version | grep "Build ID"  | cut -d ':' -f 2 | tr -d ' '
      interval: 1
      match: all
      retries: 10
      wait_for: null
  stdout:
  - |-
    show version | grep "Build ID"  | cut -d ':' -f 2 |
    tr -d ' '
    5247496
  stdout_lines: <omitted>

DOES NOT... This is the Ansible task:

- name: get installed firmware build ID to compare with config
  edgeos_command:
    commands: show version | grep "Build ID"  | cut -d ':' -f 2 | tr -d ' '
  register: installed_firmware_build_id
  tags: router-upgrade

What am I missing here?

muhi
  • 1
  • 1
  • What happens when you manually run your piped command on each host ? Any difference in output ? It looks like your `HOSTNAME2` is returning in its output the command it just ran + the output. Any configuration difference on each of the devices that would explain that ? – Zeitounator Jan 03 '20 at 09:55
  • yes I did. Exactly the same output, exactly the same automatically rendered edgeos config :( – muhi Jan 03 '20 at 10:16
  • i also checked the vyatta config - values are defaults and identical – muhi Jan 03 '20 at 12:06
  • If I just use the "show version" command, the outputs are identical. I think pipelining with the ansible edgeos module is crappy. I should use jinja filters, something like ``` "{{ cmdoutput.stdout_lines[4] | regex_search('') }}" ``` – muhi Jan 03 '20 at 13:57

1 Answers1

0

I ended up like this:

 - set fact:
  edgeos_command:
    commands: show version
  register: installed_firmware_version_raw
  tags: router-upgrade

  - set_fact:
    installed_firmware_version: "{{ (installed_firmware_version_raw.stdout[0] | regex_findall('Version:\\s+(v.+)'))[0] }}"
  tags: router-upgrade

 - set_fact:
    installed_firmware_build_id: "{{ (installed_firmware_version_raw.stdout[0] | regex_findall('Build ID:\\s+(\\d+)'))[0] }}"
  tags: router-upgrade
muhi
  • 1
  • 1