Ansible Automation Platform 2.2.1 fails with "system hostname cannot be localhost" - ansible

I keep running into the following error while installing Ansible Automation Platform 2.2:
TASK [ansible.automation_platform_installer.preflight : Ensure hostname on nodes with receptor installed is not localhost] ***
fatal: [172.16.10.13]: FAILED! => {"changed": false, "msg": "The system hostname cannot be localhost, receptor requires it to be set to something other than localhost"}
The inventory file contents:
[automationcontroller]
172.16.10.13
[automationcontroller:vars]
peers=execution_nodes
ansible_user=root
ansible_ssh_private_key_file="path to my key file"
Example inventory file from Red Hat installation guide:
[automationcontroller]
127.0.0.1 ansible_connection=local
[database]
database.example.com
[all:vars]
admin_password='<password>'
pg_password='<password>'
pg_host='database.example.com'
pg_port='5432'
pg_database='awx'
pg_username='awx'
registry_url='registry.redhat.io'
registry_username='<registry username>'
registry_password='<registry password>'
Installation with both fails with the same error.

Basic networking topology in an ip4 system consists of the total ip4 address space less certain specific adress blocks and individual addresses.
The localhost/localnet block at 127.n.n.n is routable, but only to other addresses in that block, none of which are routable beyond the confines of the local host environment.
Hence the name ‘localhost’.
Since it is impossible to network on an address space that is unrouteable to any network, i.e., literally any other host, you will find it a prerequisite activity to fully configure a proper network in which all collaborative network contributors are all routable with each other.

Apparently you are supposed to use the fqdn.
On rhel 9:
sudo hostname your-hostname
[automationcontroller]
your-hostname.example.com
[automationcontroller:vars]
peers=execution_nodes
ansible_user=root
ansible_ssh_private_key_file="path to my key file"

Related

Can we create a playbook to install a package in our own system?

I'm using Ubuntu Linux
I have created an inventory file and I have put my own system IP address there.
I have written a playbook to install the nginx package.
I'm getting the following error:
false, msg" : Failed to connect to the host via ssh: connect to host myip : Connection refused, unreachable=true
How can I solve this?
You could use the hosts keyword with the value localhost
- name: Install nginx package
hosts: localhost
tasks:
- name: Install nginx package
apt:
name: nginx
state: latest
Putting your host IP directly in your inventory treats your local machine as any other remote target. Although this can work, ansible will use the ssh connection plugin by default to reach your IP. If an ssh server is not installed/configured/running on your host it will fail (as you have experienced), as well as if you did not configure the needed credentials (ssh keys, etc.).
You don't need to (and in most common situations you don't want to) declare localhost in your inventory to use it as it is implicit by default. The implicit localhost uses the local connection plugin which does not need ssh at all and will use the same user to run the tasks as the one running the playbook.
For more information on connection plugins, see the current list
See #gary lopez answer for an example playbook to use localhost as target.

/ect/ansible file is not available in Mac OS

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
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.

hostname cannot resolved during installation of IBM private cloud ce

I installed IBM-Cloud-private-ce by following the guide https://www.ibm.com/support/knowledgecenter/SSBS6K_1.2.0/installing/install_containers_CE.html
But after I ran docker run -e LICENSE=accept --net=host -t -v "$(pwd)":/installer/cluster ibmcom/cfc-installer:1.2.0 install, I got the following error messages
task path: /installer/playbook/roles/check/tasks/main.yaml:78
fatal: [a.b.c.d] => Hostname should be resolved to a valid IP address
fatal: [a.b.c.e] => Hostname should be resolved to a valid IP address
I put the ip address as [a.b.c.d] just for confidential. Actually they are numbers here. These IP address are reachable.
By checking the ansible file, I noticed the following code
- name: Checking Hostname is resolvable
shell: ping -c 1 $(hostname) | awk -F'[()]' '{print $2;exit}'
args:
executable: /bin/bash
register: ip_out
- name: Validating Hostname is resolvable
fail: msg="Hostname should be resolved to a valid IP address"
when: ip_out.stdout in ['', '127.0.0.1', '127.0.1.1']
I found I cannot ping in the container as the image hasn't ping in it.
Is this the reason why I got the message? I appreciate if anyone could help on it.
Updated the question. Thanks #SBERENS
I tried on the 2.1.0 version and met the same issue: (for confidential reason, I used a.b.c.d as the IP address, actually the IP address are reachable)
My /etc/hosts is like the following:
127.0.0.1 localhost
127.0.1.1 e1.xx.yy.com e1
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
#puppet:
a.b.c.a puppet.xx.yy.com puppet
a.b.c.d e1.xx.yy.com e1
a.b.c.e e2.xx.yy.com e2
The cluster/hosts is like:
[master]
a.b.c.d
[worker]
a.b.c.e
[proxy]
a.b.c.e
#[management]
#4.4.4.4
The link you posted seems to be for older 1.2 level.
Please check that you are following the correct most updated installation instructions.
Latest version ICP 2.1 - CE are here:
https://www.ibm.com/support/knowledgecenter/SSBS6K_2.1.0/installing/install_ce.html
Can you please post your /etc/hosts file and the cluster/hosts file contents?
Your issue will occur in either 1.2 or 2.1.
The error is that the hostname e1.xx.yy.com resolves to a.b.c.d and 127.0.1.1. When this happens, the installer is enforcing the resolved IP to be something which is externally routable.
Is there a reason why you have the machine hostname defined on the local address in addition to a separate network IP?
Suggest removal of the line:
127.0.1.1 e1.xx.yy.com e1
from /etc/hosts. This can cause DNS confusion esp on Ubuntu.

Ansible windows fails with "Server not found in Kerberos database"

I am testing ansible (developer build) to connect to a windows machine.
ansible 2.0.0 (devel d1b98ec776)
The following command fails
ansible inh-jnambood-dt.india.mentorg.com -m win_ping -vvvv
Error is as below
bash-4.1$ ansible inh-jnambood-dt.india.mentorg.com -m win_ping -vvvv
Using /etc/ansible/ansible.cfg as config file
Loaded callback minimal of type stdout, v2.0
<inh-jnambood-dt.india.mentorg.com> ESTABLISH WINRM CONNECTION FOR USER: jnambood#MGC.MENTORG.COM on PORT 5985 TO inh-jnambood-dt.india.mentorg.com
inh-jnambood-dt.india.mentorg.com | FAILED! => {
"failed": true,
"msg": "ERROR! kerberos: (('Unspecified GSS failure. Minor code may provide more information', 851968), ('Server not found in Kerberos database', -1765328377)), plaintext: 401 Unauthorized."
jnambood is my user id MGC.MENTORG.COM is the domain
Clearly there is some step I missed. What should I do to fix this error?
That usually means that the Linux host where you're running kinit is not joined to the domain (ie, it doesn't have a properly configured computer account in the domain). The existing docs unhelpfully omit that requirement...
I've also seen this occur where the FQDN of the the host is not entered in both the command and the ansible hosts file.
Try something like:
inh-jnambood-dt.mcg.mentorg.com
HTH
I'm not using Ansible, but pywinrm directly. To get things working from a RHEL7 computer to a Windows 10 host in the domain, I changed # to / in the pywinrm code. I did this because I saw other software use HTTP/hostname and not HTTP#hostname when talking to Kerberos. Hope this is useful for somebody.
https://github.com/requests/requests-kerberos/pull/141/commits
We had this same error. For us, it was resolved by shortening the hostname to have less than 15 characters.

Vagrant: Ansible set hosts entries via provision

i have a question again. I'm looking for a possibility to set hosts entries for domains in vagrant ansible without using my local and guest hosts files.
I read something about the inventory file, so tried it. The following content is in the file itself:
[myvm]
the-vm.local
Here is the error I got from
==> myvm: Running provisioner: ansible...
ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false PYTHONUNBUFFERED=1 ansible-playbook --private-key=/Users/me/.vagrant.d/insecure_private_key --user=vagrant --limit='myvm' --inventory-file=ansible/hosts -v ansible/playbook.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
fatal: [the-vm.local] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
TASK: [Required packages present] *********************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit #/Users/me/playbook.retry
the-vm.local : ok=0 changed=0 unreachable=1 failed=0
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Any clue how to solve that or is there any other way to do it?
Thanks in upfront!
I had the same problem. The problem lies where ansible is running on our local machine and the vagrant VM is using NAT.
The answer involves setting the VM network to bridged so that ansible can resolve the hostname or ip from the machine it is executing from (Vagrantfile modification):
config.vm.network :public_network
During "vagrant up" the console will ask you to specify which network interface to bridge to.
==> default: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) en3: Thunderbolt 1
4) bridge0
5) p2p0
default: What interface should the network bridge to?
Source: http://docs.ansible.com/guide_vagrant.html

Resources