-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Conversation
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! |
@mpdehaan Thanks for your initial review. @jimi1283 I'm looking forward to see your comments, too. Thanks! |
For distribution based on systemd, the method is to call hostnamectl set-hostname That would work on Fedora, recent Mageia ( > 3 ) , Opensuse and Arch. |
In fact, looking at code, it would just work fine on those platform if you write /etc/hostname |
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. |
Tested under Fedora 19 and OpenSUSE 12.3. Not tested on ArchLinux.
Hi, I added a support for CentOS 5 (python 2.4), Fedora, OpenSUSE, and ArchLinux. @mstuivenberg did test it on RHEL 5.6. I tested it on Fedora 19 and OpenSUSE 12.3, but I did not test it on ArchLinux. Could someone test this on ArchLinux? |
@mstuivenberg did check this on RHEL6 at hnakamur/ansible-playbooks@a8718f3#commitcomment-4496179 Thanks! |
Tested successfully ...
|
Add a hostname module, which sets system's hostname.
Thanks for merging! |
Seems like it's not working with RHEL5; Submitted changes to @hnakamur for assessment; |
@mstuivenberg Thanks for pull request hnakamur/ansible-playbooks#2. |
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
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
I tried to use hostname module and I get this... Line causing the error is:
I have Ansible 1.4. My local environment is Mac OS X and remote is Vagrant Ubuntu 12.04.3 LTS. |
@jiv-e Are you sure you've got 1.4 installed? which ansible-playbook |
I moved this here: #5304 |
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, |
Hello @chestel, Thanks for your report. Could you test it? Cheers, |
Hi, @dragon3 Thanks for letting me know a pull request #5090. @chestel |
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:
|
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?