Get data from ping output in ansible - variables

I can't extract the ip from the register var after ping command from "shell" module.
ping.yml
---
- name: "Ping computers"
shell:
cmd: "ping -c1 -w 2 {{ pinging_host }}"
register: pingged_host
ignore_errors: yes
with_items:
- 192.168.1.27
- 192.168.1.42
loop_control:
loop_var: pinging_host
- name: "Result ping"
debug:
var: pingged_host
- name: " ***Ip ping"
debug:
var: pingged_host.results.value.pinging_host
...
output from jenkins:
TASK [ Result ping] **********************
ok: [computer1] => {
"pingged_host": {
"changed": true,
"failed": true,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "pinging_host",
"changed": true,
"cmd": "ping -c1 -w 2 192.168.1.27",
"delta": "0:00:00.003363",
"end": "2021-02-25 17:08:48.994930",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "ping -c1 -w 2 192.168.1.27",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"pinging_host": "192.168.1.27",
"rc": 0,
"start": "2021-02-25 17:08:48.991567",
"stderr": "",
"stderr_lines": [],
"stdout": "PING 192.168.1.27 (192.168.1.27) 56(84) bytes of data.\n64 bytes from 192.168.1.27: icmp_seq=1 ttl=128 time=0.337 ms\n\n--- 192.168.1.27 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\nrtt min/avg/max/mdev = 0.337/0.337/0.337/0.000 ms",
"stdout_lines": [
"PING 192.168.1.27 (192.168.1.27) 56(84) bytes of data.",
"64 bytes from 192.168.1.27: icmp_seq=1 ttl=128 time=0.337 ms",
"",
"--- 192.168.1.27 ping statistics ---",
"1 packets transmitted, 1 received, 0% packet loss, time 0ms",
"rtt min/avg/max/mdev = 0.337/0.337/0.337/0.000 ms"
]
},
{
"ansible_loop_var": "pinging_host",
"changed": true,
"cmd": "ping -c1 -w 2 192.168.1.42",
"delta": "0:00:02.003313",
"end": "2021-02-25 17:08:51.269047",
"failed": true,
"invocation": {
"module_args": {
"_raw_params": "ping -c1 -w 2 192.168.1.42",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"msg": "non-zero return code",
"pinging_host": "192.168.1.42",
"rc": 1,
"start": "2021-02-25 17:08:49.265734",
"stderr": "",
"stderr_lines": [],
"stdout": "PING 192.168.1.42 (192.168.1.42) 56(84) bytes of data.\n\n--- 192.168.1.42 ping statistics ---\n2 packets transmitted, 0 received, 100% packet loss, time 10ms",
"stdout_lines": [
"PING 192.168.1.42 (192.168.1.42) 56(84) bytes of data.",
"",
"--- 192.168.1.42 ping statistics ---",
"2 packets transmitted, 0 received, 100% packet loss, time 10ms"
]
}
]
}
}
TASK [ ***Result ping] *******************
ok: [computer1] => {
"pingged_host.results.value.pinging_host": "VARIABLE IS NOT DEFINED!"
}
Nota: "VARIABLE IS NOT DEFINED!" or "...template error while templating string: expected name...", I have this result when I put other path's:
pingged_host.results.value.pinging_host
pingged_host.results.pinging_host
pingged_host.results.[pinging_host]
pingged_host.results[pinging_host]
pingged_host.results['pinging_host']
How I can read "pinging_host" or "rc" from my register var???????
Thank's

Your data structure in yaml looks like this
pingged_host:
results:
- pinging_host: 192.168.1.27
rc: 0
- pinging_host: 192.168.1.42
rc: 0
Since result contains an array, you have to reference exact element of the array.
i.e to get first result you should use
- name: " {{ role_name }} | ***Ip ping"
debug:
var: pingged_host.results[0].pinging_host
To get every attribute you can use map and list filters, as explained here https://ansiblemaster.wordpress.com/2017/02/24/debug-properly-data-registered-with-a-loop/ , if you want to get all rc's, you can use the following:
- name: " {{ role_name }} | ***Ip ping"
debug:
msg: "{{ pingged_host.results|map(attribute='rc')|list }}"
resulting in:
TASK [{{ role_name }} | ***Ip ping] **********************************************************************************************************************************************
ok: [localhost] => {
"msg": [
0,
0
]
}

Related

Wait for file over ssh

I would like to do something like:
- name: Wait until the file is touched
ansible.builtin.wait_for:
path: 192.168.1.1:/home/test.txt
timeout: 300
where 192.168.1.1 is some remote host I am connected to. Is this possible?
I don't believe it's possible with wait_for module.
My workaround is to use until:
- name: Wait until file exists on remote.
shell: ssh $USER#192.168.1.1 ls /home/test.txt
register: filecheck
until: filecheck.stdout == "/home/test.txt"
retries: 10
delay: 1
I copied the file to the host while the playbook was running through the 9th attempt:
changed: [localhost] => {
"attempts": 9,
"changed": true,
"cmd": "ssh root#192.168.1.1 ls /home/test.txt",
"delta": "0:00:01.548091",
"end": "2022-08-11 15:31:05.276277",
"invocation": {
"module_args": {
"_raw_params": "ssh root#192.168.1.1 ls /home/test.txt",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": false
}
},
"msg": "",
"rc": 0,
"start": "2022-08-11 15:31:03.728186",
"stderr": "",
"stderr_lines": [],
"stdout": "/home/test.txt",
"stdout_lines": [
"/home/test.txt"
]

Ansible: Print path and contents of multiple files

I am trying to write a playbook that scans a host for the authorized_keys file, and then prints out the path and contents of the file.
Every attempt I have made and all the researching I have done and I am still unable to get the behaviour that I want, which is the following:
For each instance of the found file, print:
path to file
contents of file
Here is the playbook:
---
- name: Show File Contents
vars_prompt:
- name: host
prompt: Enter host(s) to search
private: no
- name: file
prompt: Enter file to show the contents of
private: no
hosts: "{{ host }}"
tasks:
- name: Find Files
find:
patterns: "{{ file }}"
recurse: true
paths: /
register: files_matched
- name: Cat authorized keys
shell: cat {{ item.path }}
register: cat
loop: "{{ files_matched.files }}"
- name: Print output
loop: "{{ cat | json_query('results[*].stdout') }}"
debug:
msg: "{{ item.results }}"
become: true
...
Here is the output when the above playbook is run against a single host:
TASK [Print output] ****************************************************************************************************************
ok: [ansible-testinghost.local] => {
"msg": [
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "cat /root/.ssh/authorized_keys",
"delta": "0:00:00.003527",
"end": "2022-04-10 14:56:27.867035",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "cat /root/.ssh/authorized_keys",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": {
"atime": 1649599428.4008615,
"ctime": 1648947238.992,
"dev": 64768,
"gid": 0,
"gr_name": "root",
"inode": 661181,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0600",
"mtime": 1648947238.992,
"nlink": 1,
"path": "/root/.ssh/authorized_keys",
"pw_name": "root",
"rgrp": false,
"roth": false,
"rusr": true,
"size": 0,
"uid": 0,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
"rc": 0,
"start": "2022-04-10 14:56:27.863508",
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
},
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "cat /home/ansible/.ssh/authorized_keys",
"delta": "0:00:00.003548",
"end": "2022-04-10 14:56:28.138414",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "cat /home/ansible/.ssh/authorized_keys",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": {
"atime": 1649587940.6308339,
"ctime": 1649458786.3099895,
"dev": 64768,
"gid": 1001,
"gr_name": "ansible",
"inode": 661196,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0600",
"mtime": 1649458786.3099895,
"nlink": 1,
"path": "/home/ansible/.ssh/authorized_keys",
"pw_name": "ansible",
"rgrp": false,
"roth": false,
"rusr": true,
"size": 561,
"uid": 1001,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
"rc": 0,
"start": "2022-04-10 14:56:28.134866",
"stderr": "",
"stderr_lines": [],
"stdout": "ssh key",
"stdout_lines": [
"ssh key"
]
},
{
"ansible_loop_var": "item",
"changed": true,
"cmd": "cat /home/primary-admin/.ssh/authorized_keys",
"delta": "0:00:00.003515",
"end": "2022-04-10 14:56:28.408766",
"failed": false,
"invocation": {
"module_args": {
"_raw_params": "cat /home/primary-admin/.ssh/authorized_keys",
"_uses_shell": true,
"argv": null,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"stdin": null,
"stdin_add_newline": true,
"strip_empty_ends": true,
"warn": true
}
},
"item": {
"atime": 1649587950.2066748,
"ctime": 1649495080.4039176,
"dev": 64768,
"gid": 1000,
"gr_name": "primary-admin",
"inode": 661199,
"isblk": false,
"ischr": false,
"isdir": false,
"isfifo": false,
"isgid": false,
"islnk": false,
"isreg": true,
"issock": false,
"isuid": false,
"mode": "0600",
"mtime": 1649495080.4039176,
"nlink": 1,
"path": "/home/primary-admin/.ssh/authorized_keys",
"pw_name": "primary-admin",
"rgrp": false,
"roth": false,
"rusr": true,
"size": 277,
"uid": 1000,
"wgrp": false,
"woth": false,
"wusr": true,
"xgrp": false,
"xoth": false,
"xusr": false
},
"rc": 0,
"start": "2022-04-10 14:56:28.405251",
"stderr": "",
"stderr_lines": [],
"stdout": "ssh key",
"stdout_lines": [
"ssh key"
]
}
]
}
Which I have summarised to be a list of 3 dictionaries:
"msg": [
{},
{},
{}
]
How do I get my playbook to print just the path and contents?
Thanks for your time!
Fix the last task "Print output". Otherwise, your code is working as expected. For example, given the files at the remote host for testing
shell> ssh admin#test_11 'find /tmp -name authorized_keys'
/tmp/root/.ssh/authorized_keys
/tmp/admin/.ssh/authorized_keys
shell> ssh admin#test_11 'cat /tmp/root/.ssh/authorized_keys'
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
shell> ssh admin#test_11 'cat /tmp/admin/.ssh/authorized_keys'
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
Running the playbook
shell> ansible-playbook playbook.yml
Enter host(s) to search: test_11
Enter file to show the contents of: authorized_keys
Set a list
- name: Print output
set_fact:
path_content: "{{ cat.results|
json_query('[].{path: item.path, content: stdout}') }}"
- debug:
var: path_content
gives
path_content:
- content: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
path: /tmp/root/.ssh/authorized_keys
- content: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
path: /tmp/admin/.ssh/authorized_keys
, or a dictionary
- name: Print output
set_fact:
path_content: "{{ cat.results|
json_query('[].{path: item.path, content: stdout}')|
items2dict(key_name='path', value_name='content') }}"
- debug:
var: path_content
gives
path_content:
/tmp/admin/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
/tmp/root/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
If you run the code on multiple hosts collect all results in a dictionary. For example, running the playbook
shell> ansible-playbook playbook.yml
Enter host(s) to search: test_11,test_12
Enter file to show the contents of: authorized_keys
Set the dictionary of all hosts
- name: Print output of all hosts
set_fact:
host_path_content: "{{ dict(ansible_play_hosts|
zip(ansible_play_hosts|
map('extract', hostvars, 'path_content'))) }}"
run_once: true
- debug:
var: host_path_content
gives
host_path_content:
test_11:
/tmp/admin/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
/tmp/root/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_12
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
test_12:
/tmp/admin/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_11
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13
/tmp/root/.ssh/authorized_keys: |-
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_11
ssh-rsa 111111111111111111
22222222222222222222222222
333333333333 admin#test_13

Ansible Register access invocation_module?

I have a playbook that downloads a list of files from S3, this list can be set dynamically by utilizing with_items and |default([]).
After pulling this I need to get a list of destinations of the stored files and perform other actions. I registered the var output and see that invocation module_args has the value "Dest" which is what i want to access.
I've tried things like:
debug: msg="{{ item }}"
with_items: "{{ output.results }}
Or even accessing output.invocation but get undefined variable
Task:
- name: "Download Apps from S3"
aws_s3:
bucket: "{{ resource_bucket_name }}"
object: "{{ s3_apps[item].src }}"
dest: "{{ s3_apps[item].dest }}"
mode: get
with_items: "{{ s3_apps_decl |default([]) }}"
register: output
My output variable with debug:
"msg": [
{
"ansible_loop_var": "item",
"changed": true,
"failed": false,
"invocation": {
"module_args": {
"aws_access_key": null,
"aws_secret_key": null,
"bucket": "bucket-resources",
"debug_botocore_endpoint_logs": false,
"dest": "/tmp/test_app.tgz",
"dualstack": false,
"ec2_url": null,
"encrypt": true,
"encryption_kms_key_id": null,
"encryption_mode": "AES256",
"expiry": 600,
"headers": null,
"ignore_nonexistent_bucket": false,
"marker": "",
"max_keys": 1000,
"metadata": null,
"mode": "get",
"object": "test_app.tgz",
"overwrite": "always",
"permission": [
"private"
],
"prefix": "",
"profile": null,
"region": null,
"retries": 0,
"rgw": false,
"s3_url": null,
"security_token": null,
"src": null,
"validate_certs": true,
"version": null
}
},
"item": "test_app",
"msg": "GET operation complete"
},
{
"ansible_loop_var": "item",
"changed": true,
"failed": false,
"invocation": {
"module_args": {
"aws_access_key": null,
"aws_secret_key": null,
"bucket": "bucket-resources",
"debug_botocore_endpoint_logs": false,
"dest": "/tmp/testanotherapp.spl",
"dualstack": false,
"ec2_url": null,
"encrypt": true,
"encryption_kms_key_id": null,
"encryption_mode": "AES256",
"expiry": 600,
"headers": null,
"ignore_nonexistent_bucket": false,
"marker": "",
"max_keys": 1000,
"metadata": null,
"mode": "get",
"object": "testanotherapp.spl",
"overwrite": "always",
"permission": [
"private"
],
"prefix": "",
"profile": null,
"region": null,
"retries": 0,
"rgw": false,
"s3_url": null,
"security_token": null,
"src": null,
"validate_certs": true,
"version": null
}
},
"item": "testanotherapp",
"msg": "GET operation complete"
}
]
}
My expected output would be to define a variable that outputs:
['/tmp/testanotherapp.spl'.'/tmp/test_app.tgz']
I've tried set_fact with the similar syntax as my task above however that only saves the last value...
What you should expect in output is exactly what you get since you are receiving the return values from an aws_s3 module call which you are registering in a loop.
Now, if you want to get a list of only paths of all dest you have saved on your target host, you have to extract the corresponding attribute from your data structure.
- name: Show a list of dest paths from previous run
debug:
msg: "{{ output.results | map(attribute='invocation.module_args.dest') | list }}"

Error in adding user in RabbitMQ using Ansible

I am trying to create a rabbitmq node using terraform and ansible scripts,Other scripts are executing successfully but I am facing a warning while running this script of adding a user in rabbitmq node.
[WARNING]: Module did not set no_log for update_password
failed: [rabbit-node1] (item=admin) => {
"ansible_loop_var": "item",
"changed": false,
"cmd": "/usr/sbin/rabbitmqctl -q -n rabbit list_users",
"invocation": {
"module_args": {
"configure_priv": ".*",
"force": false,
"node": "rabbit",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"permissions": [
{
"configure_priv": ".*",
"read_priv": ".*",
"vhost": "/",
"write_priv": ".*"
}
],
"read_priv": ".*",
"state": "present",
"tags": "administrator,admin",
"update_password": "on_create",
"user": "admin",
"vhost": "/",
"write_priv": ".*"
}
},
"item": "admin",
"msg": "Error:********#rabbit-node1.\n * Suggestion: start it with \"rabbitmqctl start_app\" and try again",
"rc": 70,
"stderr": "Error: rabbit application is not running on node rabbit#rabbit-node1.\n * Suggestion: start it with \"rabbitmqctl start_app\" and try again\n",
"stderr_lines": [
"Error: rabbit application is not running on node rabbit#rabbit-node1.",
" * Suggestion: start it with \"rabbitmqctl start_app\" and try again"
],
"stdout": "",
"stdout_lines": []
}
main.yml file for Creating user in Rabbitmq node using ansible:
- name: add user
rabbitmq_user:
user: "{{ item }}"
password: "{{ ADMIN_PASS }}"
tags: administrator,{{item}}
vhost: /
configure_priv: .*
write_priv: .*
read_priv: .*
state: present
with_items:
- admin

Unable to connect to dockerized redis instance from outside docker

I have the latest docker installation (without boot2docker) and I am unable to connect to a dockerized redis instance running locally. Could you please tell me what I'm doing wrong here?
Created the docker, mapped port 6379 to 127.0.0.1:6379
bash-3.2$ docker run -p 127.0.0.1:6379:6379 --name webmonitor-redis -d redis
3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9
docker ps output:
bash-3.2$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3291541d58ab redis "/entrypoint.sh redis" 14 seconds ago Up 6 seconds 127.0.0.1:6379->6379/tcp webmonitor-redis
Tried connecting from outside container (but the same host where container is running), connection failed:
bash-3.2$ ./src/redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
It works if I try to connect from another container though..
bash-3.2$ docker run -it --link webmonitor-redis:redis --rm redis sh -c 'exec redis-cli -h "$REDIS_PORT_6379_TCP_ADDR" -p "$REDIS_PORT_6379_TCP_PORT"'
172.17.0.8:6379>
Here's the docker inspect for the container:
bash-3.2$ docker inspect 3291541d58ab
[
{
"Id": "3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9",
"Created": "2015-10-03T15:48:17.818355794Z",
"Path": "/entrypoint.sh",
"Args": [
"redis-server"
],
"State": {
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 7769,
"ExitCode": 0,
"Error": "",
"StartedAt": "2015-10-03T15:48:17.954436198Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "2f2578ff984f013c9a5d6cbb6fe061ed3f73a17380a4c9b53b76d4b8da3eda7d",
"NetworkSettings": {
"Bridge": "",
"EndpointID": "b787e46d1219f36d4f1b1ea35c5f750f7174221137fb01889a26a3bc1e1c6aee",
"Gateway": "172.17.42.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"HairpinMode": false,
"IPAddress": "172.17.0.8",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:08",
"NetworkID": "30176c9c7c14a6a052af784014832a0c52b5966089d7bcfe535041569e6bb1c9",
"PortMapping": null,
"Ports": {
"6379/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "6379"
}
]
},
"SandboxKey": "/var/run/docker/netns/3291541d58ab",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null
},
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9/resolv.conf",
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9/hosts",
"LogPath": "/mnt/sda1/var/lib/docker/containers/3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9/3291541d58ab16c362f9e0cd7017d179c0bc9aef3a1323e79f1e1ca075e171c9-json.log",
"Name": "/webmonitor-redis",
"RestartCount": 0,
"Driver": "aufs",
"ExecDriver": "native-0.2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Memory": 0,
"MemorySwap": 0,
"CpuShares": 0,
"CpuPeriod": 0,
"CpusetCpus": "",
"CpusetMems": "",
"CpuQuota": 0,
"BlkioWeight": 0,
"OomKillDisable": false,
"MemorySwappiness": -1,
"Privileged": false,
"PortBindings": {
"6379/tcp": [
{
"HostIp": "127.0.0.1",
"HostPort": "6379"
}
]
},
"Links": null,
"PublishAllPorts": false,
"Dns": null,
"DnsSearch": null,
"ExtraHosts": null,
"VolumesFrom": null,
"Devices": [],
"NetworkMode": "default",
"IpcMode": "",
"PidMode": "",
"UTSMode": "",
"CapAdd": null,
"CapDrop": null,
"GroupAdd": null,
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"SecurityOpt": null,
"ReadonlyRootfs": false,
"Ulimits": null,
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"CgroupParent": "",
"ConsoleSize": [
0,
0
]
},
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"Mounts": [
{
"Name": "643a80cbd7a50cfd481acc48721b34030c8ce55ba64ac3bc161d5b330c9374d2",
"Source": "/mnt/sda1/var/lib/docker/volumes/643a80cbd7a50cfd481acc48721b34030c8ce55ba64ac3bc161d5b330c9374d2/_data",
"Destination": "/data",
"Driver": "local",
"Mode": "",
"RW": true
}
],
"Config": {
"Hostname": "3291541d58ab",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"6379/tcp": {}
},
"PublishService": "",
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"REDIS_VERSION=3.0.3",
"REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-3.0.3.tar.gz",
"REDIS_DOWNLOAD_SHA1=0e2d7707327986ae652df717059354b358b83358"
],
"Cmd": [
"redis-server"
],
"Image": "redis",
"Volumes": {
"/data": {}
},
"VolumeDriver": "",
"WorkingDir": "/data",
"Entrypoint": [
"/entrypoint.sh"
],
"NetworkDisabled": false,
"MacAddress": "",
"OnBuild": null,
"Labels": {}
}
}
]
Am I missing something here?
make sure the port 6379 on the host is forwarded to port 6379 on docker.
use -p 6379:6379 to fixed the problem:
docker run -d --name redisDev -p 6379:6379 redis
The VM has it's own IP 192.168.99.100 so I was able to connect by binding to 192.168.99.100:6379:6379 and then connecting as below.
0c4de9a25467:redis-stable electron$ ./src/redis-cli -h 192.168.99.100
192.168.99.100:6379>
docker run -p 6379:6379 -host 0.0.0.0 --name webmonitor-redis -d redis