roAl
roAl

Reputation: 193

Ansible URI not working in Gitlab CI pipeline in first run

I am facing currently a strange issue and I am not able to guess what causes it.

I wrote small Ansible scripts to test if Kafka schema-registry and connectors are running by calling their APIs.

I could run those Ansible playbooks on my local machine successfully. However, when running them in Gitlab CI pipeline (im using the same local machine as gitlab runner), the connect_test always breaks with the following error:

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"}

The strange thing, that this failed job will work when I click on retry button in CI pipeline.

Has anyone an idea about this issue? I would appreciate your help.

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

update

I replaced URI module with shell. as a result, I see the same behaviour. The initial run of the pipeline will fail and retrying the job will fix it

Upvotes: 0

Views: 1672

Answers (1)

Kingindanord
Kingindanord

Reputation: 2036

maybe you are restarting the services in a previous job, take in mind that kafka connect needs generally more time to be available after the restart. Try to pause ansible after you restart the service for a minute or so.

Upvotes: 1

Related Questions