# unable to connect to jenkins

**URL:** <https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176>\
**Category:** Ansible Project\
**Created:** [June 30, 2023, 7:22am UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176 "2023-06-30T07:22:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 7:22am UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/1 "2023-06-30T07:22:18Z")

</div>

I am getting below error when trying to connect to jenkins url using ansible\_jenkins\_info module

msg": “Unable to connect to Jenkins server, Unable to authenticate with any scheme:\nauth(kerberos) HTTPSConnectionPool(host=‘\<[jenkins.com](http://jenkins.com)\>._‘, port=443): Max retries exceeded with url: /api/json (Caused by NewConnectionError(’\<urllib3.connection.HTTPSConnection object at 0x7f4fcb26bd30\>: Failed to establish a new connection: [Errno -2] Name or service not known’,))\nauth(basic) HTTPSConnectionPool(host=’ \<[jenkins.com](http://jenkins.com)\>._ ‘, port=443): Max retries exceeded with url: /api/json (Caused by NewConnectionError(’\<urllib3.connection.HTTPSConnection object at 0x7f4fcb26b9e8\>: Failed to establish a new connection: [Errno -2] Name or service not known’,))”,

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 30, 2023, 11:28am UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/2 "2023-06-30T11:28:08Z")

</div>

This indicates some DNS resolution issue on the system where this task executes.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 6:09pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/3 "2023-06-30T18:09:05Z")

</div>

thankyou, I have some typos, fixed that issue. BUt in the same playbook I trying to use loops and access both the urls with respective user and password and print the job info, but only one url response is working. other one is failing with error. if I remove the working url and try with accessing the failed user details, it works. I believe some thing I might have missed in the loop.

---

<div class="post-metadata">

**Author:** ![tin](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@tin](https://forum.ansible.com/u/tin)\
**Post date:** [June 30, 2023, 6:40pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/4 "2023-06-30T18:40:04Z")

</div>

Is your Jenkins services hosted on [jenkins.com](http://jenkins.com) ? The error indicate that’s the host you are trying to connect to.

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 30, 2023, 7:15pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/5 "2023-06-30T19:15:51Z")

</div>

Hi Narmada,

I would suggest you to remove include\_vars if you want to read the variables from files. Instead of that you can simplify the task like -

```auto
vars:
urls:
- url: url1
username: username1
password_file: group_vars/password1.yml
- url: url2
username: username2
password_file: group_vars/password2.yml
tasks:
- debug:
msg: "{{ (lookup('file', url_item.password_file )|from_yaml).password }}"
loop: "{{ urls }}"
loop_control:
loop_var: url_item

```

I am assuming your password\*.yml file looks like this =

```auto
# cat group_vars/password1.yml
---
password: sample1

```

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 7:46pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/6 "2023-06-30T19:46:57Z")

</div>

That’s right, that how my password file looks like  
Let me try your suggestion and update you.  
Thankyou

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 7:48pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/7 "2023-06-30T19:48:07Z")

</div>

Also I would I use that password item in the below play

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 11:09pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/8 "2023-06-30T23:09:42Z")

</div>

any suggestions how I can use the password from this debug as variable in next play

- debug:  
msg: “{{ (lookup(‘file’, url\_item.password\_file )|from\_yaml).password }}”

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [June 30, 2023, 11:42pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/9 "2023-06-30T23:42:01Z")

</div>

Hi Narmada,

I just showed you an example. You can directly use `jekins_job_info` in a similar way.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [June 30, 2023, 11:45pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/10 "2023-06-30T23:45:17Z")

</div>

Thanks bunch, I used this for token: “{{ (lookup(‘file’, url\_item.password\_file )|from\_yaml).password }}” it worked…

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 1, 2023, 4:34pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/11 "2023-07-01T16:34:21Z")

</div>

Abhijeet, I need one more help, from the above playbook I am trying to check if the job exists on 2 jenkins urls.  
Now, I am trying to configure job if the doesn’t exist on any of the jenkins, for this I have to look for job if exists. I am little confused how to check the condition.

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 3, 2023, 12:36am UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/12 "2023-07-03T00:36:32Z")

</div>

I am having hard time getting the when condition work  
I have couple of application names have 2 separate jenkins urls. My playbook has to check if the job exists on both the urls and then create the new job. I am successful until checking and getting the data if the job exists or not. NOw when trying to write the when condition I am failing.  
scenario 1 : I have 2 repos, and 2 urls . in this case the job exists on one of the jenkins and then it has to skip the next step creating the new jenkins job , I need to get when condition working.  
“msg”: “Job URLs: [‘[https://test.com/job/repo1.teamCI/](https://test.com/job/repo1.teamCI/)’]” “msg”: “Job URLs: ”  
scenario 2: in this case the job doesn’t exist on any of the url, then it should go and create the job on specific jenkins which I mentioned in next play

“msg”: “Job URLs: ”  
“msg”: “Job URLs: ”

TASK [Display Jobs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> (item={‘changed’: False, ‘jobs’: , ‘invocation’: {‘module\_args’: {‘glob’: 'repo1._', ‘url’: ‘[https://url1.com](https://url1.com)’, ‘user’: ‘account’, ‘token’: ‘tokenvalue’, ‘validate\_certs’: False, ‘name’: None, ‘color’: None, ‘password’: None}}, ‘failed’: False, ‘item’: [{‘url’: ‘[https://url1.com](https://url1.com)’, ‘username’: ‘account’, ‘password\_file’: ‘group\_vars/password1.yml’}, ‘repo1’], ‘ansible\_loop\_var’: ‘item’}) =\> {  
“ansible\_loop\_var”: “item”,  
“item”: {  
“ansible\_loop\_var”: “item”,  
“changed”: false,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“color”: null,  
“glob”: "repo1._",  
“name”: null,  
“password”: null,  
“token”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“url”: “url”,  
“user”: “acount”,  
“validate\_certs”: false  
}  
},  
“item”: [  
{  
“password\_file”: “group\_vars/password1.yml”,  
“url”: “[https://url1.com](https://url1.com)”,  
“username”: “account”  
},  
“release.sqls”  
],  
“jobs”:   
},  
“item.jobs”:   
}

I am checking item.jobs attribute

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 3, 2023, 12:39am UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/13 "2023-07-03T00:39:44Z")

</div>

If the job already exist

“item.jobs”: [{ “fullname”: “repo2”, “jobs”: , “name”: “repo2”, “url”: “[https://url2/job/repo2/](https://warpjenkins.teslamotors.com/job/tms2.api.teamCI/)” }

---

<div class="post-metadata">

**Author:** ![Narmada\_Karthika](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@Narmada\_Karthika](https://forum.ansible.com/u/Narmada_Karthika)\
**Post date:** [July 5, 2023, 5:23pm UTC](https://forum.ansible.com/t/unable-to-connect-to-jenkins/38176/14 "2023-07-05T17:23:58Z")

</div>

Yea, I fixed this issue after posting it
