Ansible Unable to connect to windows - jenkins

When I'm trying to execute ansible windows -m win_ping -i inv.txt from Jenkins job, I'm getting the following error.
windows | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='xxx.xx.x.xx', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fe822b97370>, 'Connection to xxx.xx.x.xx timed out. (connect timeout=30)'))",
"unreachable": true
}
And when I try to run this command from another ansible host, the command gives a output:
windows | SUCCESS => {
"changed": false,
"ping": "pong"
}

Related

ansible.legacy.setup\n - module failed to execute on jenkins pipeline

I'm using Jenkins to launch a simple Ansible Pipeline (to create a folder on localhost as follow
name: Play1
hosts: localhost
become: true
remote_user: ec2-user
tasks:
- name: Create directory
file:
path: /home/ec2-user/Newfolder
state: directory
group: ec2-user
owner: ec2-user
mode: 0700
But when i build the pipeline I got this error message:
TASK [Gathering Facts] *********************************************************
fatal: [localhost]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"failed": true, "module_stderr": "sudo: a password is required\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}
Have you an idea about this error please ?
I think you are not providing the sudo password, and the ansible_user is not already configured for passwordless sudo. Following is the error from the snippet you provided.
{"failed": true, "module_stderr": "sudo: a password is required\n",
In the playbook, you have provided become: true and remote_user: ec2-user
become: true
remote_user: ec2-user
So your ec2-user is not having permission to become a root user without password being passed. You can run sudo -l command to check what a user can do with his current sudo configurations.
If you do not want to change the sudoers file, then simply pass -K flag to the playbook while execution to get prompted for the sudo password.
-K, --ask-become-pass
However, the user ec2-user must be in a sudoer file; without it you will an error like the below regardless of supplying ec2-user password via -K
ec2-user is not in the sudoers file

CLOSED - Ansible task on docker container - Docker command not found in PATH

I am trying to execute some tasks on docker containers. I have 1 host dev.com.peer.2 with at least 1 container dev.com.peer.2.container1. I can't run even a debug task :
- debug:
msg: "Hello world from the Docker container '{{ inventory_hostname }}'"
I encounter this error :
fatal: [dev.com.peer.2.container1]: FAILED! => {"msg": "docker command not found in PATH"}
I understand the error but I don't get why ansible would call the docker command in the container and not on the host as defined. What did I do wrong ?
The host is defined in a previous task as follow :
TASK [debug] ****************************************************************************************************************************************************************
Monday 24 May 2021 09:25:21 +0200 (0:00:00.205) 0:10:06.777 ************
ok: [dev.com.peer.2] => {
"host_docker_inventory_list": {
"add_host": {
"groups": [
"remote_container"
],
"host_name": "dev.com.peer.2.container1",
"host_vars": {
"ansible_connection": "docker",
"ansible_docker_extra_args": "-H=tcp://*host_ip*:*api_port*",
"ansible_user": "root",
"inventory_dir": "/home/user/dev/deploy/inventories/dev",
"parenthostname": "dev.com.peer.2"
}
},
"changed": true,
"failed": false
}
}
I am running ansible 2.9.6 w/ python version = 3.8.5

Ansible invoked via Jenkins error "Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock"

Looks like this question has been asked before but I have done what other people suggested yet, still get the error.
The user I am running jenkins on is called: jenkinsuser
docker is installed with version: Docker version 20.10.4, build d3cb89e
jenkinsuser is already in docker group:
$> grep docker /etc/group
docker:x:497:jenkinsuser
My ansible script looks like this:
---
- hosts: localhost
connection: local
gather_facts: no
tasks:
- name:
"get the username running the deploy"
local_action: command whoami
register: username_on_the_host
- debug: var=username_on_the_host
- name:
"Download tensorflow/serving image"
shell: docker pull tensorflow/serving
become: false
and when I invoke it using Jenkins it errors with:
TASK [get the username running the deploy] *************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
"username_on_the_host": {
"changed": true,
"cmd": [
"whoami"
],
"delta": "0:00:00.014707",
"end": "2021-03-05 16:29:34.138218",
"failed": false,
"rc": 0,
"start": "2021-03-05 16:29:34.123511",
"stderr": "",
"stderr_lines": [],
"stdout": "jenkinsuser",
"stdout_lines": [
"jenkinsuser"
]
}
}
TASK [Download tensorflow/serving image] ***************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "docker pull tensorflow/serving", "delta": "0:00:00.120564", "end": "2021-03-05 16:29:50.688169", "msg": "non-zero return code", "rc": 1, "start": "2021-03-05 16:29:50.567605", "stderr": "Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=tensorflow%2Fserving&tag=latest: dial unix /var/run/docker.sock: connect: permission denied", "stderr_lines": ["Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.24/images/create?fromImage=tensorflow%2Fserving&tag=latest: dial unix /var/run/docker.sock: connect: permission denied"], "stdout": "Using default tag: latest", "stdout_lines": ["Using default tag: latest"]}
Am i missing something??
Also, I can not run as root on the jenkins server so i can't run it as root.
$> stat /var/run/docker.sock
File: ‘/var/run/docker.sock’
Size: 0 Blocks: 0 IO Block: 4096 socket
Device: 14h/20d Inode: 558480959 Links: 1
Access: (0660/srw-rw----) Uid: ( 0/ root) Gid: ( 497/ docker)
Access: 2021-03-05 20:01:04.712848585 +0000
Modify: 2021-03-02 22:00:01.367880977 +0000
Change: 2021-03-02 22:00:01.376880979 +0000
Birth: -

Fly: Failed to ping docker registry

I am trying to run a simple build by passing input task to the concourse. Here is my fly command,
fly -t tutorial e -c inputs_required.yml -i some-important-input=.
and my yml file,
---
platform: linux
image_resource:
type: docker-image
source: {repository: busybox}
inputs:
- name: some-important-input
run:
path: ls
args: ['-alR']
I am getting the below error message,
resource script '/opt/resource/check []' failed: exit status 1
stderr:
failed to ping registry: 2 error(s) occurred:
* ping https: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
* ping http: Get http://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
errored
Please note that I am not behind a proxy. I am also not able to ping https://registry-1.docker.io/v2/.
The simple reason is your host cannot reach docker registry which is docker.io by default.
I am not familiar with fly. But I think the image source in your yaml file { repository:busybox} should be a specific image which could be used in command docker pull.
For addition, you may try a local image on your host first. Then try a remote image in some remote registry.

unable to load ansible playbook to a docker host (host unreachable)

im trying to : ansible-playbook install_docker.yml
and keep getting the following error:
TASK [setup] *******************************************************************
fatal: [172.17.0.2]: UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true}
my playbook looks like this
---
- hosts: all
vars:
docker_opts: >
- "H unix:///var/run/docker.sock"
- "H tcp://0.0.0.0:2375"
remote_user: root
roles:
- angstwad.docker.ubuntu
im providing the docker host ip by copying the ip using:
docker inspect apacheweb1 | grep IPAddress
how can i reach the docker host?

Resources