/ect/ansible file is not available in Mac OS

12/12/2019

I used pip to install Ansible in MacOS. But I cannot find the /etc/ansible folder. Neither the inventory file.

I want to run my playbook in minikube environment. But the playbook returns,

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: 192.168.99.105

How to solve this issue?

--
ansible
kubernetes
macos
minikube

1 Answer

12/13/2019

I looked into this matter and using Ansible for managing minikube is not an easy topic. Let me elaborate on that:

The main issue is cited below:

Most Ansible modules that execute under a POSIX environment require a Python interpreter on the target host. Unless configured otherwise, Ansible will attempt to discover a suitable Python interpreter on each target host the first time a Python module is executed for that host. -- Ansible Docs

What that means is that most of the modules will be unusable. Even ping

Steps to reproduce:

  • Install Ansible
  • Install Virtualbox
  • Install minikube
  • Start minikube
  • SSH into minikube
  • Configure Ansible
  • Test

Install Ansible

As the original poster said it can be installed through pip. For example: $ pip3 install ansible

Install VirtualBox

Please download and install appropriate version for your system.

Install minikube

Please follow this site: Kubernetes.io

Start minikube

You can start minikube by invoking command:

$ minikube start --vm-driver=virtualbox

Parameter --vm-driver=virtualbox is important because it will be useful later for connecting to the minikube.

Please wait for minikube to successfully deploy on the Virtualbox.

SSH into minikube

It is necessary to know the IP address of minikube inside the Virtualbox. One way of getting this IP is:

  • Open Virtualbox
  • Click on the minikube virtual machine for it to show
  • Enter root for account name. It should not ask for password
  • Execute command: $ ip a | less and find the address of network interface. It should be in format of 192.168.99.XX

From terminal that was used to start minikube please run below command:

$ minikube ssh

Command above will ssh to newly created minikube environment and it will store a private key in location: HOME_DIRECTORY .minikube/machines/minikube/id_rsa

id_rsa will be needed to connect to the minikube

Try to login to minikube by invoking command: ssh -i PATH_TO/id_rsa docker@IP_ADDRESS

If login has happened correctly there should be no issues with Ansible

Configure Ansible

For using ansible-playbook 2 files will be needed:

  • Hosts file with information about hosts
  • Playbook file with statements what you require from Ansible to do

Example hosts file:

[minikube_env]  
minikube ansible_host=IP_ADDRESS ansible_ssh_private_key_file=./id_rsa

[minikube_env:vars]
ansible_user=docker
ansible_port=22

The ansible_ssh_private_key_file=./id_rsa will tell Ansible to use ssh key from file with correct key to this minikube instance. Note that this declaration will need to have id_rsa file in the same location as rest of the files.

Example playbook:

- name: Playbook for checking connection between hosts  
  hosts: all  
  gather_facts: no  

  tasks:
  - name: Task to check the connection  
    ping:

You can test the connection by invoking command:

$ ansible-playbook -i hosts_file ping.yaml

Above command should fail because there is no Python interpreter installed.

fatal: [minikube]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "module_stderr": "Shared connection to 192.168.99.101 closed.\r\n", "module_stdout": "/bin/sh: /usr/bin/python: No such file or directory\r\n", "msg": "The module failed to execute correctly, you probably need to set the interpreter.\nSee stdout/stderr for the exact error", "rc": 127}

There is a successful connection between Ansible and minikube but there is no Python interpreter to back it up.

There is a way to use Ansible without Python interpreter.

This Ansible documentation is explaining the use of raw module.

-- Dawid Kruk
Source: StackOverflow