Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a hostname module, which sets system's hostname. #3940

Merged
merged 8 commits into from
Nov 7, 2013

Conversation

hnakamur
Copy link
Contributor

I send this pull request in response to
https://groups.google.com/d/msg/ansible-project/komqS4WdqHU/cRfWiMnCR3cJ

Currently implemented on only Debian, Ubuntu, RedHat and CentOS.
Unfortunately I'm not familiar about settings hostnames on other systems.

I appreciate your feedbacks.

By the way, I searched the mailing list for prior discussions about a module to set hostname, but couldn't find them.
https://groups.google.com/forum/?hl=ja#!forum/ansible-project
@mpdehaan Could you point me to the url of the discussions?

@mpdehaan
Copy link
Contributor

This code generally looks good but I have not tested it yet. It will be good to have a hostname module.

I'm ok with it doesn't set it on all platforms if it will raise an error when it can't be used on those platforms and use fail_json to explain it.

The extra syslogging should be removed as Ansible will already do that for you when a module is invoked, and we don't want any more verbosity than that.

This will also allow the "execute_command" function to be replaced with just module.run_command directly.

The "with" statement is Python 2.5 and later, so this will need to be written to not use "with" to support Python 2.4 systems.

@jimi1283 may have some other comments, this is just some initial review and some things that need to be fixed before we can accept this.

Thanks!

@hnakamur
Copy link
Contributor Author

@mpdehaan Thanks for your initial review.
I modified the hostname module.
I tested it on CentOS 6.4 and Ubuntu 12.04.
I confirmed it raises an error on Darwin with message "hostname module cannot be used on platform Darwin".
Could you take another look?

@jimi1283 I'm looking forward to see your comments, too.

Thanks!

@mscherer
Copy link
Contributor

For distribution based on systemd, the method is to call hostnamectl set-hostname

That would work on Fedora, recent Mageia ( > 3 ) , Opensuse and Arch.

@mscherer
Copy link
Contributor

In fact, looking at code, it would just work fine on those platform if you write /etc/hostname

@mpdehaan
Copy link
Contributor

I'm sorry for the late reply, we have been swamped by pull requests and strategic features lately and are just now digging out :)

I'm still very interested in this one.

If you can update this to handle systemd distributions on the above that would be great as I suspect many people will be testing on those platforms.

@hnakamur
Copy link
Contributor Author

Hi, I added a support for CentOS 5 (python 2.4), Fedora, OpenSUSE, and ArchLinux.

@mstuivenberg did test it on RHEL 5.6.
hnakamur/ansible-playbooks#1

I tested it on Fedora 19 and OpenSUSE 12.3, but I did not test it on ArchLinux.
I tried to create a test environment for ArchLinux with vagrant boxes listed on http://www.vagrantbox.es/
https://dl.dropboxusercontent.com/u/31112574/arch64-20130801.box
https://googledrive.com/host/0B_BLFE4aPn5zUVpyaHdLanVnMTg/vagrant-archlinux-2013-8.box
but failed.

Could someone test this on ArchLinux?
Thanks.

hnakamur referenced this pull request in hnakamur/ansible-playbooks Nov 3, 2013
@hnakamur
Copy link
Contributor Author

hnakamur commented Nov 3, 2013

@mstuivenberg did check this on RHEL6 at hnakamur/ansible-playbooks@a8718f3#commitcomment-4496179 Thanks!

@jctanner
Copy link
Contributor

jctanner commented Nov 7, 2013

Tested successfully ...

TASK: [hostname name="{{inventory_hostname}}"] ******************************** 
failed: [el5.lab.net] => {"failed": true}
msg: hostname module cannot be used on platform Linux (Redhat)
...ignoring
ok: [el4.lab.net] => {"changed": false, "name": "el4.lab.net"}
ok: [el6.lab.net] => {"changed": false, "name": "el6.lab.net"}
failed: [opensuse10.lab.net] => {"failed": true}
msg: hostname module cannot be used on platform Linux (Suse)
...ignoring

jctanner added a commit that referenced this pull request Nov 7, 2013
Add a hostname module, which sets system's hostname.
@jctanner jctanner merged commit 01a054d into ansible:devel Nov 7, 2013
@hnakamur
Copy link
Contributor Author

hnakamur commented Nov 8, 2013

Thanks for merging!

@mstuivenberg
Copy link

Seems like it's not working with RHEL5; Submitted changes to @hnakamur for assessment;

@hnakamur
Copy link
Contributor Author

hnakamur commented Nov 9, 2013

@mstuivenberg Thanks for pull request hnakamur/ansible-playbooks#2.
I merged it to my project and sent the same pull request to the ansible project #4868

EvanK pushed a commit to evolution/genesis-wordpress that referenced this pull request Nov 13, 2013
Both modules should be (hopefully) in ansible's 1.4 release, until then providing them here as custom lib modules:

* hostname module, see ansible/ansible#3940
* replace module, see ansible/ansible#4889
EvanK pushed a commit to evolution/genesis-wordpress that referenced this pull request Nov 13, 2013
Both modules should be (hopefully) in ansible's 1.4 release, until then providing them here as custom lib modules:

* hostname module, see ansible/ansible#3940
* replace module, see ansible/ansible#4889
@jiv-e
Copy link

jiv-e commented Dec 13, 2013

I tried to use hostname module and I get this...
ERROR: hostname is not a legal parameter in an Ansible task or handler

Line causing the error is:

  • hostname: name=test

I have Ansible 1.4. My local environment is Mac OS X and remote is Vagrant Ubuntu 12.04.3 LTS.
No tips here: http://www.ansibleworks.com/docs/modules.html#hostname

@gundalow
Copy link
Contributor

@jiv-e Are you sure you've got 1.4 installed?
ansible-playbook --version

which ansible-playbook
ls /library/system/hostname

@jiv-e
Copy link

jiv-e commented Dec 15, 2013

I moved this here: #5304

@chestel
Copy link

chestel commented Dec 18, 2013

Hi @hnakamur,

I'd like to use your great hostname module on all my Linux servers. Some of them are the Amazon distro derived from Redhat. They are fundamentally the same RedHat under the covers and so I'm sure the RedHatStrategy would work fine with them.

However ansible_distribution is defined as Amazon and so returns an unimplemented_error.

Would it be appropriate to use ansible_os_family instead of ansible_distribution to determine strategy?

If so, this module would pick up support for some more distros for free.

Cheers,
Leo

@hnakamur
Copy link
Contributor Author

Hello @chestel,

Thanks for your report.
I added a support for Amazon Linux the hostname module.
hnakamur@47b19e9

Could you test it?
If it works successfully, I will send a pull request to the ansible project.

Cheers,
Hiroaki

@dragon3
Copy link
Contributor

dragon3 commented Dec 18, 2013

Hi @hnakamur , @chestel

I already send a pull request #5090 for support Amazon Linux and that was merged.
Which ansible version do you use?

@hnakamur
Copy link
Contributor Author

Hi, @dragon3

Thanks for letting me know a pull request #5090.
I didn't notice it and made a mistake when I fetched and merged the latest ansible source.

@chestel
Please forget about my commit hnakamur/ansible@47b19e9 and just use the latest commit.

@chestel
Copy link

chestel commented Dec 18, 2013

I've pulled v 1.5 and Amazon hosts now work with the hostname module.

Thank you both very much!

On 18 December 2013 14:48, Hiroaki Nakamura notifications@github.comwrote:

Hi, @dragon3 https://github.com/dragon3

Thanks for letting me know a pull request #5090#5090
.
I didn't notice it and made a mistake when I fetched and merged the latest
ansible source.

@chestel https://github.com/chestel
Please forget about my commit hnakamur/ansible@47b19e9hnakamur@47b19e9and just use the latest commit.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3940#issuecomment-30846842
.

@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants