I have two machine, local host ubuntu, and client centOS 7.
I have added those lines into: /etc/ansible/hosts
[linux]
192.168.122.1
[linux:vars]
ansible_user=user
ansible_password=123456
and changed uncommented 1 line in ansible.cfg:
# uncomment this to disable SSH key host checking
host_key_checking = False
Still when I do:
ansible all -m ping
192.168.122.1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.122.1 port 22: Connection timed out",
unreachable": true
}
what should I do ?
the password and user in hosts file is what i use to log into the other machine
Check your firewalls and selinux. Port 22 is not accepting the connection. It's not a password issue, it's a networking issue.
I have problem to manage influxdb through ansible using "influxdb_database" module. Even though it printouts error about python dependency, it is failing only when container where ansible playbook runs is run on diff VM from one where influxdb is hosted. I run ansible playbook from docker container, and if I run container on the host where influxdb is installed, it works fine - it is managing to create db. But, when same container (created from same image as one mentioned before) runs on different VM from one where influxdb is hosted, it is failing with error pasted below. So I am confused now with the error about python dependency and do not understand where the problem is.
Ansible playbook:
hosts: "tag_deployment_sysmiromis:&tag_service_tick_yes"
user: centos
become: yes
tasks:
- name: Install InfluxDB package
yum: name="influxdb-{{ frame_tick_influxdb_package_version }}" state=present disable_gpg_check=yes
register: frame_yum_run
retries: 10
until: frame_yum_run is success
- name: Restrict InfluxDB user login
user:
name: "influxdb"
group: "influxdb"
shell: /sbin/nologin
- name: Enable InfluxDB service
systemd:
name: influxdb
enabled: yes
state: started
- name: Create InfluxDB data directory
file:
path: "{{ frame_tick_influxdb_data_directory }}"
owner: influxdb
group: influxdb
state: directory
mode: 0750
- name: Create database
influxdb_database:
hostname: localhost
database_name: miroslav
Ansible log on failed task
TASK [Create database] ***********************************************************************************************************************************************************
task path: /app/lib/ansible/playbooks/influx.yml:6
Using module file /usr/lib/python3.8/site-packages/ansible/modules/database/influxdb/influxdb_database.py
Pipelining is enabled.
<10.246.44.196> ESTABLISH SSH CONNECTION FOR USER: centos
<10.246.44.196> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="centos"' -o ConnectTimeout=30 -o ControlPath=/root/.ansible/cp/be4c96d801 10.246.44.196 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-brzvkupumuacfsjirccgazqszuzzfwwx ; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<10.246.44.196> (1, b'\n{"msg": "Failed to import the required Python library (influxdb) on frame-tick10-246-44-196\'s Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter", "failed": true, "exception": "Traceback (most recent call last):\\n File \\"/tmp/ansible_influxdb_database_payload_IrdxhN/ansible_influxdb_database_payload.zip/ansible/module_utils/influxdb.py\\", line 23, in <module>\\n from influxdb import InfluxDBClient\\nImportError: No module named influxdb\\n", "invocation": {"module_args": {"username": "root", "retries": 3, "use_udp": true, "proxies": {}, "database_name": "miroslav", "hostname": "localhost", "udp_port": 4444, "ssl": false, "state": "present", "timeout": null, "password": "root", "validate_certs": true, "port": 8086}}}\n', b'OpenSSH_8.1p1, OpenSSL 1.1.1g 21 Apr 2020\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug2: resolve_canonicalize: hostname 10.246.44.196 is address\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2147\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\n')
<10.246.44.196> Failed to connect to the host via ssh: OpenSSH_8.1p1, OpenSSL 1.1.1g 21 Apr 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 10.246.44.196 is address
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote
debug3: mux_client_request_session: entering
debug3: mux_client_request_alive: entering
debug3: mux_client_request_alive: done pid = 2147
debug3: mux_client_request_session: session request sent
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_influxdb_database_payload_IrdxhN/ansible_influxdb_database_payload.zip/ansible/module_utils/influxdb.py", line 23, in <module>
from influxdb import InfluxDBClient
ImportError: No module named influxdb
fatal: [10.246.44.196]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"database_name": "miroslav",
"hostname": "localhost",
"password": "root",
"port": 8086,
"proxies": {},
"retries": 3,
"ssl": false,
"state": "present",
"timeout": null,
"udp_port": 4444,
"use_udp": true,
"username": "root",
"validate_certs": true
}
}
}
MSG:
Failed to import the required Python library (influxdb) on frame-tick10-246-44-196's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter
sounds like you're dealing with the same issue as me. I was struggling to find out what was wrong then I read the requirements and saw this. I'm using a newer version of influxdb than this module supports so I get the same error as you
Requirements
The below requirements are needed on the host that executes this module.
python >= 2.6
influxdb >= 0.9 & <= 1.2.4
requests
https://docs.ansible.com/ansible/latest/modules/influxdb_database_module.html
UPDATE:
I have been able to find a way to interact with influx DB using the api instead of the modules since they don't work. This involves editing the influxdb.conf to enable using the API
# modifying the influxdb.conf is required to be able to use the influxDB API
- name: Enable http
lineinfile:
path: /etc/influxdb/influxdb.conf
regexp: 'Determines whether HTTP endpoint is enabled.'
line: ' enabled = true'
- name: Enable bind address :8086
lineinfile:
path: /etc/influxdb/influxdb.conf
regexp: '# bind-address = ":8086"'
line: ' bind-address = ":8086"'
- name: Restart influxdb,
systemd:
name: influxdb
state: restarted
- name: Create influxDB database via api
uri:
url: "http://localhost:8086/query"
method: POST
body: 'q=CREATE DATABASE "grafanadb"'
body_format: form-urlencoded
- name: create root user in influxdb
uri:
url: "http://localhost:8086/query"
method: POST
body: "q=CREATE USER user WITH PASSWORD 'pass' WITH ALL PRIVILEGES"
- name: create grafana user in influxdb
uri:
url: "http://localhost:8086/query"
method: POST
body: "q=CREATE USER grafana WITH PASSWORD 'grafana'"
- name: Grant all privileges to grafana user on grafanadb
uri:
url: "http://localhost:8086/query"
method: POST
body: "q=GRANT ALL ON grafanadb TO grafana"
body_format: form-urlencoded
In order to get influxdb_database module working you have to make sure you have influxdb-python installed on your machine. It is also recommended to have influxdb installed as you might want to directly access the database from the command line.
For CentOS7/RHEL7 installations this can be done as follows:
yum install python-pip
pip install influxdb
CentOS8/RHEL8:
dnf install python3-pip
pip3 install influxdb
Note: You have to use a different python version as the default python interpreter is different for CentOS7 and 8. Therefore influxdb_database python interpreter will be different too.
Therefore, the playbook would look something like this:
- name: Install applications for CentOS 7
yum:
name:
- influxdb
- python-pip
- name: Install applications for CentOS 8
yum:
name:
- influxdb
- python3-pip
- name: Install required pip packages
pip:
name:
- influxdb
For debian/ubuntu setups you might do the following:
apt-get install python-influxdb
or
- name: Install applications for CentOS
apt:
name:
- python-influxdb
If you are trying to connect to a remote InfluxDB you should ensure that you are authenticating over SSL. You have to manually enable this as it is not enabled by default.
This is what a remote influx database creation would thus look like:
- name: Create database using custom credentials
influxdb_database:
hostname: "{{influxurl}}"
username: "{{influxusername}}"
password: "{{influxpassword}}"
database_name: "{{influxdbv7}}"
port: "{{influxport}}"
ssl: yes
validate_certs: yes
Note: I have tested this setup with CentOS7/8. It possibly works fine with Ubuntu/Debian setups too. For some reason CentOS7 required me to disable validate_certs, otherwise it fails. Possibly its a bug.
Tested version:
Database: InfluxDB version 1.8.3
Ansible: version 2.9
What I was missing is influxdb installed in targeted host.Once it is installed, influxdb ansible module start working fine.
Also struggled with this issue. Downgrading the version of the requests python package helped me.
pip install requests==2.6.0
(2.25.1 did not work for me)
I am trying to connect to remote solaris machine from a linux server using ssh but not able to connect to the solaris machine. I am using below ssd command to connect to the solaris machine
ssh <host_name>
After giving this command, I am not getting any prompt for username and password. Is it the limitation for linux to solaris connection ??
The output is:
root#host> ssh -v user#solaris_host
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to solaris_host [solaris_host] port 22.
debug1: connect to address solaris_host port 22: Connection timed out
ssh: connect to host solaris_host port 22: Connection timed out
Go over following steps
Check the network connectivity with your target, e.g. ping.
Check if the port 22 is open on your remote host e.g. nmap -A 192.168.0.5/32 -p 22
Check if ssh daemon is running on your target svcs ssh
Come back, when the problem still exists.
I have a virtual linux build running on qemu (It runs drop bear as ssh client.) and I am trying to copy some modules I wrote to it using scp using the following command:
scp -vvv -p 2222 wd/day10/int_mod.ko root#localhost:/lib/modules/3.13.5/int_mod.ko
And I get Connection refused error more specifically (I forwarded 2222 to 22 of virtual machine.):
Executing: program /usr/bin/ssh host localhost, user root, command scp -v -p -d -t /lib/modules/3.13.5/int_mod.ko
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused
lost connection
What I don't understand is I can easily connect to ssh using
ssh -p 2222 root#localhost
I can connect without any problem.
ssh and scp use different options for specifying the port. From the ssh man page:
[-p port]
From the scp man page:
[-P port]
scp uses capital P. Notice how your debug output says port 22 connection refused when you are trying to connect to port 2222.
Problem is that , ssh package is not installed completely!
you must install ssh and openssh-client so on... with Synaptic Package Manager!
in Synaptic Package Manager , first type ssh in search filter and mark ssh. then click on Apply Button to install ssh services for server and client.
by this way your problem will fixed 100 Percentage!!!
see bellow Please:
We have been using Ubuntu VM's on Azure for some time now and rarely had a any problems. However, one of the VMs has gone bonkers lately. Out of the blue, the Ubuntu VM starts rejecting the public key -
ssh -i ~/azure.key abc#xyz.cloudapp.net
Permission denied (publickey).
Verbose gives me even more confusing signs -
~$ ssh -i -v -v -v ~/azure.key abc#xyz.cloudapp.net
Warning: Identity file -v not accessible: No such file or directory.
OpenSSH_5.9p1 Debian-5ubuntu1.1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
ssh: Could not resolve hostname /home/abc/azure.key: Name or service not known
Wondering if anyone saw this problem or can suggest ideas/solutions?
How about the following?
$ ssh -i ~/azure.key -v -v -v abc#xyz.cloudapp.net