0

这是我在这里的第一个问题,我很兴奋:)

这可能是一个菜鸟问题,但我不明白......

我正在尝试使用 Gitlab-CI 和 Ansible升级 Edgerouter 固件(https://www.ui.com/edgemax/edgerouter-pro/ )。这些阶段是绝对相同的,但相同任务的标准输出、相同的 ansible.cfg、相同的 gitlab-runner、相同的管道等不同:

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>

奇迹般有效!但:

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>

不...这是 Ansible 任务:

- 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

我在这里想念什么?

4

1 回答 1

0

我最终是这样的:

 - 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
于 2020-01-07T14:55:15.983 回答