【问题标题】:Ansible URI not working in Gitlab CI pipeline in first runAnsible URI 在第一次运行时在 Gitlab CI 管道中不起作用
【发布时间】:2021-01-17 05:04:20
【问题描述】:

我目前面临一个奇怪的问题,我无法猜测是什么原因造成的。

我编写了小型 Ansible 脚本来测试 Kafka 模式注册表和连接器是否通过调用其 API 来运行。

我可以在本地机器上成功运行这些 Ansible playbook。但是,当在 Gitlab CI 管道中运行它们时(我使用与 gitlab 运行器相同的本地计算机),connect_test 总是会因以下错误而中断:

fatal: [xx.xxx.x.x]: FAILED! => {"changed": false, "elapsed": 0, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [Errno 111] Connection refused>", "redirected": false, "status": -1, "url": "http://localhost:8083"}

奇怪的是,当我点击 CI 管道中的重试按钮时,这个失败的工作会起作用。

有人知道这个问题吗?非常感谢您的帮助。

schema_test.yml

---
- name: Test schema-registry
  hosts: SCHEMA
  become: yes
  become_user: root
    
  tasks:
  - name: list schemas
    uri:
        url: http://localhost:8081/subjects
    register: schema

  - debug:
      msg: "{{ schema }}"

connect_test.yml

---
- name: Test connect
  hosts: CONNECT
  become: yes
  become_user: root
    
  tasks:
  - name: check connect
    uri:
        url: http://localhost:8083
    register: connect

  - debug:
      msg: "{{ connect }}"

.gitlab-ci.yml


test-connect:
  stage: test
  script:
    - ansible-playbook connect_test.yml
  tags:
    - gitlab-runner

test-schema:
  stage: test
  script:
    - ansible-playbook schema_test.yml
  tags:
    - gitlab-runner

更新

我用 shell 替换了 URI 模块。结果,我看到了相同的行为。管道的初始运行将失败,重试作业将修复它

【问题讨论】:

标签: ansible uri gitlab-ci gitlab-ci-runner


【解决方案1】:

也许您正在重新启动之前作业中的服务,请记住,kafka connect 通常需要更多时间才能在重新启动后可用。重启服务一分钟左右后尝试暂停ansible。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2022-08-11
    • 1970-01-01
    • 2012-12-28
    • 2022-01-03
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多