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?
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
As the original poster said it can be installed through pip. For example: $ pip3 install ansible
Please download and install appropriate version for your system.
Please follow this site: Kubernetes.io
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.
It is necessary to know the IP address of minikube inside the Virtualbox. One way of getting this IP is:
$ ip a | less
and find the address of network interface. It should be in format of 192.168.99.XXFrom 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
For using ansible-playbook
2 files will be needed:
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.