0

I would like to setup ansible on my Mac. I've done something similar in GNS3 and it worked but here there are more factors I need to take into account. so I have the Ansible installed. I added hostnames in /etc/hosts and I can ping using the hostnames I provided there.

I have created ansible folder which I am going to use and put ansible.cfg inside:

[defaults]
hostfile = ./hosts
host_key_checking = false
timeout = 5
inventory = ./hosts

In the same folder I have hosts file:

[tp-lab]
lab-acc0

When I try to run the following command: ansible tx-edge-acc0 -m ping

I am getting the following errors:

[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
[WARNING]: Unhandled error in Python interpreter discovery for host tx-edge-acc0: unexpected output from Python interpreter discovery
[WARNING]: sftp transfer mechanism failed on [tx-edge-acc0]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: scp transfer mechanism failed on [tx-edge-acc0]. Use ANSIBLE_DEBUG=1 to see detailed information
[WARNING]: Platform unknown on host tx-edge-acc0 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information.
tx-edge-acc0 | FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "module_stderr": "Shared connection to tx-edge-acc0 closed.\r\n",
    "module_stdout": "\r\nerror: unknown command: /bin/sh\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 0

Any idea what might the problem here? much appreciated

1 Answers1

0

At first glance it seems that you ansible controller does not load configuration files (especially ansible.cfg) when playbook is fired.

(From documentation) Ansible searches for configuration files in the following order, processing the first file it finds and ignoring the rest:

  1. $ANSIBLE_CONFIG if the environment variable is set.
  2. ansible.cfg if it’s in the current directory.
  3. ~/.ansible.cfg if it’s in the user’s home directory.
  4. /etc/ansible/ansible.cfg, the default config file.

Edit: For peace of mind it is good to use full paths

EDIT Based on comments

$ cat /home/ansible/ansible.cfg
[defaults]
host_key_checking = False
inventory = /home/ansible/hosts  # <-- use full path to inventory file

$ cat /home/ansible/hosts
[servers]
server-a
server-b

Command & output:

# Supplying inventory host group! 
$ ansible servers -m ping
server-a | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
server-b | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
Facty
  • 472
  • 4
  • 12
  • I managed to bring it up however cannot perform the basic ansible ping. Please check my update and thanks for helping – Patryk Petryszen Mar 04 '21 at 14:45
  • Is python installed on target server? If so tweak interpreter, eg `ansible_python_interpreter=/usr/bin/python3` – Facty Mar 04 '21 at 15:22
  • No there's not Python installed on a target server. It's just a ping so shouldn't be needed? – Patryk Petryszen Mar 04 '21 at 15:25
  • Yes, because you are running command `ping` on server mentioned in inventory file. You can verify it by using some remote web server (eg facebook.com, google.com) in your inventory filese – Facty Mar 04 '21 at 15:56
  • Ok. I have now created a playbook and enabled the netconf on the remote switch but still getting the following: FAILED! => {"changed": false, "msg": "Connection type ssh is not valid for netconf_get module. Valid connection type is netconf."} – Patryk Petryszen Mar 04 '21 at 16:22
  • This is for completely new issue.... But [HERE](https://docs.ansible.com/ansible/latest/network/getting_started/network_differences.html) is where you have to start – Facty Mar 04 '21 at 22:30