unable to connect to jenkins

243 views
Skip to first unread message

Narmada Karthika

unread,
Jun 30, 2023, 3:22:19 AM6/30/23
to Ansible Project
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>.*', 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>.*  ', 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',))",

Dick Visser

unread,
Jun 30, 2023, 7:28:42 AM6/30/23
to ansible...@googlegroups.com
On Fri, 30 Jun 2023 at 09:22, Narmada Karthika <chitt...@gmail.com> wrote:

> msg": "Unable to connect to Jenkins server, Unable to authenticate with any scheme:\nauth(kerberos) HTTPSConnectionPool(host='<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>.* ', 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',))",

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

Narmada Karthika

unread,
Jun 30, 2023, 2:09:06 PM6/30/23
to Ansible Project
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.

---
 - name: Access URLs with Different User-Password Combinations
   hosts: localhost
   gather_facts: false

   vars:
     urls:
       - url: <url1>
         username: <username1>
         password_file: group_vars/password1.yml
       - url: <url1>
         username: <username2>
         password_file: group_vars/password2.yml

   tasks:
     - name: Include Password Variables
       include_vars:
         file: "{{ url_item.password_file }}"
       loop: "{{ urls }}"
       loop_control:
         loop_var: url_item


     - name: Access URLs
       community.general.jenkins_job_info:
         glob: "reponame.*"
         url: "{{ url_item.url }}"
         user: "{{ url_item.username }}"
         token: "{{ password }}"
         validate_certs: false
       loop: "{{ urls }}"
       loop_control:
         loop_var: url_item
       vars:
         - password: "{{ url_item.password_file }}"
       register: response

     - name: Print Response
       debug:
         var: response

Abhijeet Kasurde

unread,
Jun 30, 2023, 3:16:19 PM6/30/23
to ansible...@googlegroups.com
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 -

```
  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 =
```
# cat group_vars/password1.yml
---
password: sample1
```


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e5d45eb6-54e7-49e4-a261-92657c03ef10n%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Narmada Karthika

unread,
Jun 30, 2023, 3:47:22 PM6/30/23
to ansible...@googlegroups.com
That’s right, that how my password file looks like 
Let me try your suggestion and update you. 
Thankyou 

--
 Thanks,
Narmada Karthika Chitturi
 

Narmada Karthika

unread,
Jun 30, 2023, 3:48:32 PM6/30/23
to ansible...@googlegroups.com
Also I would I use that password item in the below play

On Fri, Jun 30, 2023 at 12:16 PM Abhijeet Kasurde <akas...@redhat.com> wrote:

Narmada Karthika

unread,
Jun 30, 2023, 7:09:42 PM6/30/23
to Ansible Project

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

Abhijeet Kasurde

unread,
Jun 30, 2023, 7:42:27 PM6/30/23
to ansible...@googlegroups.com
Hi Narmada,

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



--
Thanks,
Abhijeet Kasurde

Narmada Karthika

unread,
Jun 30, 2023, 7:45:17 PM6/30/23
to Ansible Project
Thanks  bunch, I used this for token:  "{{ (lookup('file', url_item.password_file )|from_yaml).password }}" it worked..

Narmada Karthika

unread,
Jul 1, 2023, 12:34:21 PM7/1/23
to Ansible Project
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.

Narmada Karthika

unread,
Jul 2, 2023, 8:36:32 PM7/2/23
to Ansible Project
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/']" "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', 'user': 'account', 'token': 'tokenvalue', 'validate_certs': False, 'name': None, 'color': None, 'password': None}}, 'failed': False, 'item': [{'url': '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",
                "username": "account"
            },
            "release.sqls"
        ],
        "jobs": []
    },
    "item.jobs": []
}


I am checking item.jobs attribute 

Narmada Karthika

unread,
Jul 2, 2023, 8:39:45 PM7/2/23
to Ansible Project
If the job already exist

"item.jobs": [ { "fullname": "repo2", "jobs": [], "name": "repo2", "url": "https://url2/job/repo2/" }

tin...@gmail.com

unread,
Jul 5, 2023, 1:23:03 PM7/5/23
to Ansible Project
Is your Jenkins services hosted on jenkins.com ?   The error indicate that's the host you are trying to connect to.

Narmada Karthika

unread,
Jul 5, 2023, 1:24:19 PM7/5/23
to ansible...@googlegroups.com
Yea, I fixed this issue after posting it

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages