msg: hostname module cannot be used on platform Linux (Centos linux)

754 views
Skip to first unread message

Joanna Delaporte

unread,
Nov 11, 2015, 3:44:02 PM11/11/15
to Ansible Project
Hello everyone,

I am getting the following error while attempting to run a Galaxy role that was published for EL 7. My target host is an AWS EC2 instance running CentOS 7.0.1406. The only info I have found about this error was an issue report on GitHub closed in 2014...and I haven't found anything else online. Is there a configuration issue I am missing?

Error: 

TASK: [gregswift.ipaserver | Hard set the hostname] *************************** 
failed: [ipaddress] => {"failed": true}
msg: hostname module cannot be used on platform Linux (Centos linux)


Host distro details from setup:
"ansible_distribution": "CentOS", 
        "ansible_distribution_major_version": "7", 
        "ansible_distribution_release": "Core", 
        "ansible_distribution_version": "7.0.1406",


Ansible version:
$ ansible --version                                        
ansible 1.9.3
  configured module search path = /usr/share/ansible

Greg Swift

unread,
Nov 12, 2015, 10:51:16 PM11/12/15
to Ansible Project
Fwiw, i built this role against centos7 and just ran it fresh against an updated box monday. I'm gonna check it again now that i saw this.

Greg Swift

unread,
Nov 13, 2015, 1:48:07 AM11/13/15
to Ansible Project
So I have no idea why the ostname module would be behaving like that. Looking at the module it has lots of distribution coverage.  I just tested hostname on ansible 1.9.4 and

"ansible_distribution": "CentOS", "ansible_distribution_major_version": "7", "ansible_distribution_release": "Core", "ansible_distribution_version": "7.1.1503",

-greg

On Thu, Nov 12, 2015 at 9:51 PM Greg Swift <greg...@gmail.com> wrote:
Fwiw, i built this role against centos7 and just ran it fresh against an updated box monday. I'm gonna check it again now that i saw this.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/29610778-7298-4161-acdc-68e048c13050%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joanna Delaporte

unread,
Nov 13, 2015, 8:58:08 AM11/13/15
to Ansible Project
Your role is awesome. Thanks for writing it...I ran into another issue with firewalld not being installed by default on AWS. I submitted a pull request this morning to include installing and starting firewalld. 

The shell command hostname seemed to worked fine, but in my research about it, supposedly I will lose the hostname on reboot. So you probably don't want that change in your role. I don't know yet what the solution is for the hostname module.

Joanna Delaporte

unread,
Nov 13, 2015, 11:52:26 AM11/13/15
to Ansible Project
Okay, I just repeated the error on a recently-built CentOS 7.0.1406 machine that is on my physical network, not an AWS machine.

 "ansible_distribution": "CentOS",
        "ansible_distribution_major_version": "7",
        "ansible_distribution_release": "Core",
        "ansible_distribution_version": "7.0.1406",

When I run it with both machines:
PLAY [ipaservers] *************************************************************

GATHERING FACTS ***************************************************************
<obfuscatedip2> REMOTE_MODULE setup
<obfuscatedip5> REMOTE_MODULE setup
ok: [obfuscatedip2]
ok: [obfuscatedip5]

TASK: [ansible-ipaserver | Hard set the hostname] *****************************
<obfuscatedip2> REMOTE_MODULE hostname name=obfuscatedhostname2.my.domain.edu
<obfuscatedip5> REMOTE_MODULE hostname name=ip-172-31-23-203.us-west-2.compute.internal
failed: [obfuscatedip2] => {"failed": true}

msg: hostname module cannot be used on platform Linux (Centos linux)
failed: [obfuscatedip5] => {"failed": true}

msg: hostname module cannot be used on platform Linux (Centos linux)

FATAL: all hosts have already failed -- aborting


Reading through the module code, it seems I am getting dumped right into UnimplementedStrategy class, but I don't understand yet how it's deciding which OS and distribution version it's looking at, before getting to the UnimplementedStrategy. It's the first Ansible module that I've ever looked at under the hood.

Joanna

Joanna Delaporte

unread,
Nov 13, 2015, 11:54:53 AM11/13/15
to Ansible Project
I updated to Ansible 1.9.4, and I still have the same issue on both target hosts.

Ivan S. Freitas

unread,
Nov 13, 2015, 12:02:36 PM11/13/15
to ansible...@googlegroups.com
I would bet the module is trying to set the hostname using the
features of the old Centos' init system, then fails since it has
transitioned to systemd. Can you set the hostname manually with a
'command' action calling hostnamectl? You could also try the modules
from the 2.0-rc releases or git to see if this was already fixed
there.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4632e3af-f7c2-4f93-b73e-db147196884f%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Ivan Sichmann Freitas

Brian Coca

unread,
Nov 13, 2015, 1:06:17 PM11/13/15
to Ansible Project
the module checks the platform and version to determine which approach
it uses, for centos if the version is >= 7 it will use systemd, for
other versions it uses hostname + file editing.



--
Brian Coca

Greg Swift

unread,
Nov 13, 2015, 2:08:20 PM11/13/15
to ansible...@googlegroups.com

Joanna found that it has something to do with the AWS CentOS7 install. I'm assuming based on her PR that it doesnt seem to have hostnamectl available, which seems weird?

https://github.com/gregswift/ansible-ipaserver/pull/1


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Greg Swift

unread,
Nov 13, 2015, 2:11:32 PM11/13/15
to ansible...@googlegroups.com

Hrm..  Hadnt seen her recreation on nonaws email.  Now I'm stumped again.  Hostnamectl is provided directly by systemd.

Joanna Delaporte

unread,
Nov 13, 2015, 2:14:06 PM11/13/15
to Ansible Project
Yes, I can tell that's how it's supposed to work. However, it's like my hosts don't even get past the distribution match, wherever that happens in the code...they get dumped straight into the UnimplementedStrategy class for error handling. If the code were recognizing CentOS, it would be using either systemd or RedHat strategy. UnimplementedStrategy is not an outcome for CentOS. 

Joanna Delaporte

unread,
Nov 13, 2015, 2:27:07 PM11/13/15
to Ansible Project
Actually, it happens both on a local install of CentOS 7.0.1406 and AWS's CentOS7.0.1406.

hostnamectl works fine on my AWS host.

Brian Coca

unread,
Nov 13, 2015, 2:41:24 PM11/13/15
to Ansible Project
the 'magic' gets done in the load_platform_subclass, which matches the
platform name to a class of the same name + Hostname, which then sets
the strategy class, which actually implements the way of updating
hostname.

to figure out platform name it uses platform.system() built in from
python. can you do test the output of this in your instance? also
platform.linux_distribution() and platform.dist() which might be used
as fallbacks.

--
Brian Coca

Joanna Delaporte

unread,
Nov 13, 2015, 4:10:19 PM11/13/15
to Ansible Project
HI Brian,

Thanks! Both hosts had the same responses. Here's the result:

>>> print(platform.system())
Linux
>>> print(platform.linux_distribution())
('CentOS Linux', '7.0.1406', 'Core')
>>> print(platform.dist())
('centos', '7.0.1406', 'Core')

So, if the module is first looking at platform.system and taking any answer it receives, the only answer the module receives from this distribution version is "Linux".

Joanna Delaporte

unread,
Nov 13, 2015, 4:18:40 PM11/13/15
to Ansible Project
Interestingly, my ubuntu laptop also responds with just "Linux" to the platform.system() call.

Unfortunately, it appears that I cannot get CentOS 7.1 yet on AWS...I think Gregswift mentioned that worked for him today. I could test it next week at work with a physical install to identify the issue further, if that's helpful.

Joanna Delaporte

unread,
Nov 13, 2015, 4:40:44 PM11/13/15
to Ansible Project
I was wrong about CentOS 7.1 not being available...it is now the CentOS version you can get on AWS, as of fairly recently. I am about to test it now.
Message has been deleted

Joanna Delaporte

unread,
Nov 13, 2015, 4:44:23 PM11/13/15
to Ansible Project

TASK: [ansible-ipaserver | Hard set the hostname] *****************************
failed: [xxxx2] => {"failed": true}

msg: hostname module cannot be used on platform Linux (Centos linux)
failed: [xxxx5] => {"failed": true}

msg: hostname module cannot be used on platform Linux (Centos linux)
failed: [xxxx3] => {"failed": true}

msg: hostname module cannot be used on platform Linux (Centos linux)

Python output:
>>> print(platform.system())
Linux
>>> print(platform.dist())
('centos', '7.1.1503', 'Core')
>>> print(platform.linux_
distribution())
('CentOS Linux', '7.1.1503', 'Core')

Brian Coca

unread,
Nov 13, 2015, 6:09:09 PM11/13/15
to Ansible Project
he... 'CentOS Linux' != 'CentOSLinux'

we might just need to strip spaces in the detection.
--
Brian Coca

Joanna Delaporte

unread,
Nov 13, 2015, 6:31:57 PM11/13/15
to Ansible Project
Hi Greg,

Did it work for you this morning? I just tried with the same version of ansible control machine and host target and it still failed for me.

Joanna Delaporte

unread,
Nov 13, 2015, 6:35:50 PM11/13/15
to Ansible Project
Oh, good. You found something that makes sense as a cause for this problem! I'm still not sure why it worked for Gregswift earlier, and not me, though.

Joanna

Brian Coca

unread,
Nov 13, 2015, 6:40:43 PM11/13/15
to Ansible Project
so from the code, this should work when ansible_distribution":
"CentOS" but not when ansible_distribution": "CentOS Linux"

--
Brian Coca

Joanna Delaporte

unread,
Nov 13, 2015, 7:01:22 PM11/13/15
to Ansible Project
There's a class for 'Centos' at line 449, and another for 'Centos linux' at line 458, if you are looking at the Hostname module.

Brian Coca

unread,
Nov 13, 2015, 10:04:53 PM11/13/15
to Ansible Project
So i checked again, i had misread the code it does not match class
name but the declared distribution variable inside, this SHOULD match
all versions of Centos.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4f9b1dac-aa95-4446-9ec7-6706de8b7c0b%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Brian Coca

unread,
Nov 13, 2015, 10:58:34 PM11/13/15
to Ansible Project
just tested on a new 7.1 vm and hostname module works w/o any issues.


--
Brian Coca

Joanna Delaporte

unread,
Nov 13, 2015, 11:57:05 PM11/13/15
to ansible...@googlegroups.com

What version Ansible are you using? I only have the AWS instance (no other installs) I provisioned today that's 7.1 right now, but it's the latest one to have failed.

I am wondering if the version of python on my control machine would make a difference. I don't know why it would, but it's odd that every (Centos) host I point to has the same problem, when you and gregswift have both succeeded with 7.1 targets. My control machine is Slackware 14.1. Its Python version is 2.7.3.

I'll mull it over and likely try using a different control machine next...Ubuntu or CentOS.

I should write a playbook to clone all my repos/roles from bitbucket, github, and galaxy so it's easier to migrate controllers.

Thanks!
Joanna

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/c6DkdqHU6h4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Brian Coca

unread,
Nov 14, 2015, 12:25:02 AM11/14/15
to Ansible Project
in this case the version of python on ansible machine should not
matter, the module executes on the target machine. The version of
ansible might matter as many changes were made to hostname module, I'm
using 2.0/devel from git.

--
Brian Coca

Joanna Delaporte

unread,
Nov 17, 2015, 4:40:49 PM11/17/15
to Ansible Project
I did a fresh install on a new CentOS 7.1.1503. I got the same error response to the hostname module from my Slackware control machine.

I installed ansible 1.9.3 and git cloned enough over to my Ubuntu 14.04 laptop to rerun the same playbook against the same CentOS 7.1 target. The error was gone. All my CentOS targets respond just fine to my Ubuntu control machine. So...something is wonky with the control machine. It is running Slackware, so I'm not surprised. 

Thanks for troubleshooting with me!
Joanna
Reply all
Reply to author
Forward
0 new messages