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)
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
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.
TASK: [ansible-ipaserver | Hard set the hostname] *****************************
REMOTE_MODULE hostname name=obfuscatedhostname2.my.domain.edu
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.
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.
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.
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?
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.
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.
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”.
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.
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)
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.