Ansible URI在首次运行时无法在Gitlab CI管道中运行

时间:2020-10-01 13:02:30

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

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

我编写了小的Ansible脚本,通过调用它们的API来测试Kafka模式注册表和连接器是否正在运行。

我可以在本地计算机上成功运行这些Ansible剧本。但是,在Gitlab CI管道中运行它们时(即使用与gitlabRunner相同的本地计算机), 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

更新

我用外壳替换了URI模块。结果,我看到了相同的行为。管道的初始运行将失败,重试该作业将解决该问题

1 个答案:

答案 0 :(得分:1)

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