I am getting below error while invoking ansible playbook from Jenkins

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "[https://ec2.ap-northeast-1.amazonaws.com/](https://ec2.ap-northeast-1.amazonaws.com/)"
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.6/site-packages/urllib3/connection.py\", line 160, in _new_conn\n    (self._dns_host, self.port), self.timeout, **extra_kw\n  File \"/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py\", line 84, in create_connection\n    raise err\n  File \"/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py\", line 74, in create_connection\n    sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused

It’s error 111 connection refused . Check port 22 from controller to target servers .

thanks for your reply

Playbook is working fine from Linux box while the trigger playbook from Jenkins and getting this error and Jenkins has 22 port open status.

What playbook are we talking about?

I didn’t see any in your email.

I wrote the playbook for creating a resource on AWS environments, I am using the IAM CrossAccount role for this. I ran the playbook from EC2 Linux instances, it has created the resource on the AWS child account but invoking playbook from Jenkins, I am getting boto3 endpoint issue. I attached my sample playbook for your references.

I think the issue is with how you configure your environment wrt proxies. Apparently you need that, but it didn’t work, as your error pointed out.

That first command task is probably where you try to set those vars, but that won’t work.

See
https://docs.ansible.com/ansible/latest/user_guide/playbooks_environment.html

I tried multiple ways but I am not getting error messages while running playbook in EC2 Linux instances the same playbook throwing error and just I modified my the playbook.

  • name: EC2 instance creation
    hosts: localhost
    connection: local
    gather_facts: flase
    vars:
    proxy_env:
    http_proxy: http://localhost:
    https_proxy: http://localhost:
    NO_PROXY: 169.254.169.254

tasks:

  • sts_assume_role:
    role_arn: “arn:aws:iam::xxxxxxxxxxxxx:role/XXXXXXXXXX_CrossAccount_Role”
    role_session_name: “iopec2test”
    region: ap-northeast-1
    register: assumed_ec2_role
    environment: “{{ proxy_env }}”
    ignore_unreachable: yes