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

**URL:** <https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737>\
**Category:** Ansible Project\
**Tags:** aws, galaxy-ng\
**Created:** [November 11, 2015, 8:44pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737 "2015-11-11T20:44:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 11, 2015, 8:44pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/1 "2015-11-11T20:44:02Z")

</div>

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 i[ssue report on GitHub](https://github.com/ansible/ansible/issues/8102) 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

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [November 13, 2015, 3:51am UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/2 "2015-11-13T03:51:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [November 13, 2015, 6:47am UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/3 "2015-11-13T06:47:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 1:58pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/4 "2015-11-13T13:58:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 4:52pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/5 "2015-11-13T16:52:26Z")

</div>

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 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
 REMOTE\_MODULE setup  
 REMOTE\_MODULE setup  
ok: [obfuscatedip2]  
ok: [obfuscatedip5]

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.

Joanna

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 4:54pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/6 "2015-11-13T16:54:52Z")

</div>

I updated to Ansible 1.9.4, and I still have the same issue on both target hosts.

---

<div class="post-metadata">

**Author:** ![Ivan\_S\_Freitas](https://avatars.discourse-cdn.com/v4/letter/i/e99b99/32.png) [@Ivan\_S\_Freitas](https://forum.ansible.com/u/Ivan_S_Freitas)\
**Post date:** [November 13, 2015, 5:02pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/7 "2015-11-13T17:02:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 13, 2015, 6:06pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/8 "2015-11-13T18:06:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [November 13, 2015, 7:08pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/9 "2015-11-13T19:08:03Z")

</div>

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](https://github.com/gregswift/ansible-ipaserver/pull/1)[://](https://github.com/gregswift/ansible-ipaserver/pull/1)[github.com](https://github.com/gregswift/ansible-ipaserver/pull/1)[/gregswift/](https://github.com/gregswift/ansible-ipaserver/pull/1)[ansible-ipaserver](https://github.com/gregswift/ansible-ipaserver/pull/1)[/pull/1](https://github.com/gregswift/ansible-ipaserver/pull/1)

---

<div class="post-metadata">

**Author:** ![Greg\_Swift](https://avatars.discourse-cdn.com/v4/letter/g/34f0e0/32.png) [@Greg\_Swift](https://forum.ansible.com/u/Greg_Swift)\
**Post date:** [November 13, 2015, 7:11pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/10 "2015-11-13T19:11:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 7:14pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/11 "2015-11-13T19:14:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 7:27pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/12 "2015-11-13T19:27:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 13, 2015, 7:41pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/13 "2015-11-13T19:41:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 9:10pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/14 "2015-11-13T21:10:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 9:18pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/15 "2015-11-13T21:18:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 9:40pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/16 "2015-11-13T21:40:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 9:44pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/17 "2015-11-13T21:44:23Z")

</div>

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’)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 13, 2015, 11:08pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/18 "2015-11-13T23:08:59Z")

</div>

he... 'CentOS Linux' != 'CentOSLinux'

we might just need to strip spaces in the detection.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 11:31pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/19 "2015-11-13T23:31:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdelaporte](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jdelaporte/32/366_2.png) [@jdelaporte](https://forum.ansible.com/u/jdelaporte)\
**Post date:** [November 13, 2015, 11:35pm UTC](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737/20 "2015-11-13T23:35:50Z")

</div>

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

[Next page](https://forum.ansible.com/t/msg-hostname-module-cannot-be-used-on-platform-linux-centos-linux/19737.md?page=2)
