From 36de211ca5ff9a2c0add03ff923a5d43788c0ae6 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sat, 9 Apr 2016 20:35:43 -0400 Subject: import ansible-hostname role Pretty ridiculous that this is required --- roles/hostname/LICENSE | 19 +++++++++++++++++++ roles/hostname/README.md | 25 +++++++++++++++++++++++++ roles/hostname/defaults/main.yml | 3 +++ roles/hostname/tasks/main.yml | 24 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 roles/hostname/LICENSE create mode 100644 roles/hostname/README.md create mode 100644 roles/hostname/defaults/main.yml create mode 100644 roles/hostname/tasks/main.yml (limited to 'roles/hostname') diff --git a/roles/hostname/LICENSE b/roles/hostname/LICENSE new file mode 100644 index 0000000..c177445 --- /dev/null +++ b/roles/hostname/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2014 Sergey Korolev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/roles/hostname/README.md b/roles/hostname/README.md new file mode 100644 index 0000000..5f52972 --- /dev/null +++ b/roles/hostname/README.md @@ -0,0 +1,25 @@ +hostname +======== + +Set hostname via Ansible hostname module and updates /etc/hosts with hostname and domain. + +Requirements +------------ + +Ansible version 1.4 with modules _hostname_ and _template_. Ansible module _hostname_ currently implemented on only Debian, Ubuntu, RedHat and CentOS. + +Role Variables +-------------- + + * *hostname_name* - new hostname (not FQDN, before first dot) + * *hostname_domain* - new domain name + +License +------- + +MIT + +Author Information +------------------ + +Sergey Korolev () diff --git a/roles/hostname/defaults/main.yml b/roles/hostname/defaults/main.yml new file mode 100644 index 0000000..ec58975 --- /dev/null +++ b/roles/hostname/defaults/main.yml @@ -0,0 +1,3 @@ +--- +hostname_fqdn: "{{ansible_fqdn}}" +hostname_name: "{{hostname_fqdn.split('.').0}}" diff --git a/roles/hostname/tasks/main.yml b/roles/hostname/tasks/main.yml new file mode 100644 index 0000000..02094f0 --- /dev/null +++ b/roles/hostname/tasks/main.yml @@ -0,0 +1,24 @@ +--- +- name: Keep temporary old hostname in /etc/hosts + lineinfile: + dest=/etc/hosts + regexp="^127\.0\.1\.1(.*)" + line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}\1" + state=present + backup=yes + backrefs=yes + when: ansible_hostname != hostname_name + tags: [configuration,hostname] + +- name: Set hostname + hostname: name={{ hostname_name }} + when: hostname_name is defined + tags: [configuration,hostname] + +- name: Update /etc/hosts + lineinfile: + dest=/etc/hosts + regexp="^127\.0\.1\.1" + line="127.0.1.1{{'\t'}}{{ hostname_name }}{% if hostname_name != hostname_fqdn %}{{'\t'}}{{ hostname_fqdn }}{% endif %}" + state=present + tags: [configuration,hostname] -- cgit v1.2.3