aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-04-09 20:35:43 -0400
committerbnewbold <bnewbold@robocracy.org>2016-04-09 20:35:45 -0400
commit36de211ca5ff9a2c0add03ff923a5d43788c0ae6 (patch)
tree396932784bfb252be460384ea43df10847896059
parentde3755c284411432c7565fa0f01f1487abe65aaf (diff)
downloadinfra-36de211ca5ff9a2c0add03ff923a5d43788c0ae6.tar.gz
infra-36de211ca5ff9a2c0add03ff923a5d43788c0ae6.zip
import ansible-hostname role
Pretty ridiculous that this is required
-rw-r--r--roles/hostname/LICENSE19
-rw-r--r--roles/hostname/README.md25
-rw-r--r--roles/hostname/defaults/main.yml3
-rw-r--r--roles/hostname/tasks/main.yml24
4 files changed, 71 insertions, 0 deletions
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 (<korolev.srg@gmail.com>)
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]