summaryrefslogtreecommitdiffstats
path: root/roles/hostnames
diff options
context:
space:
mode:
Diffstat (limited to 'roles/hostnames')
-rw-r--r--roles/hostnames/tasks/main.yaml43
-rw-r--r--roles/hostnames/templates/records.template.yaml28
2 files changed, 21 insertions, 50 deletions
diff --git a/roles/hostnames/tasks/main.yaml b/roles/hostnames/tasks/main.yaml
index bf2fafb97..bb45445f5 100644
--- a/roles/hostnames/tasks/main.yaml
+++ b/roles/hostnames/tasks/main.yaml
@@ -1,27 +1,26 @@
---
- - name: Setting master(s) hostname
- hostname: name="{% for thishost in groups['masters'] %}{% if inventory_hostname == thishost %}master{{ counter }}.{{ dns_domain }}{% endif %}{% set counter = counter + 1 %}{% endfor %}"
- when: "'masters' in group_names"
+- name: Setting Hostname Fact
+ set_fact:
+ new_hostname: "{{ custom_hostname | default(inventory_hostname) }}"
- - name: Setting facts for masters
- set_fact: ansible_hostname="{% for thishost in groups['masters'] %}{% if inventory_hostname == thishost %}master{{ counter }}{% endif %}{% set counter = counter + 1 %}{% endfor %}"
- when: "'masters' in group_names"
+- name: Setting FQDN Fact
+ set_fact:
+ new_fqdn: "{{ new_hostname }}.{{ dns_domain }}"
- - name: Setting node(s) hostname
- hostname: name="{% for thishost in groups['nodes'] %}{% if inventory_hostname == thishost %}node{{ counter }}.{{ dns_domain }}{% endif %}{% set counter = counter + 1 %}{% endfor %}"
- when: "'nodes' in group_names"
+- name: Setting hostname and DNS domain
+ hostname: name="{{ new_fqdn }}"
- - name: Setting facts for nodes
- set_fact: ansible_hostname="{% for thishost in groups['nodes'] %}{% if inventory_hostname == thishost %}node{{ counter }}{% endif %}{% set counter = counter + 1 %}{% endfor %}"
- when: "'nodes' in group_names"
+- name: Check for cloud.cfg
+ stat: path=/etc/cloud/cloud.cfg
+ register: cloud_cfg
- - name: "Templating records"
- become: false
- template:
- src: "{{ role_path }}/templates/records.template.yaml"
- dest: "/tmp/records.yaml"
- force: yes
- delegate_to: localhost
-
- - name: "Updating hostname facts"
- setup: filter=ansible_hostname
+- name: Prevent cloud-init updates of hostname/fqdn (if applicable)
+ lineinfile:
+ dest: /etc/cloud/cloud.cfg
+ state: present
+ regexp: "{{ item.regexp }}"
+ line: "{{ item.line }}"
+ with_items:
+ - { regexp: '^ - set_hostname', line: '# - set_hostname' }
+ - { regexp: '^ - update_hostname', line: '# - update_hostname' }
+ when: cloud_cfg.stat.exists == True
diff --git a/roles/hostnames/templates/records.template.yaml b/roles/hostnames/templates/records.template.yaml
deleted file mode 100644
index 2f2420464..000000000
--- a/roles/hostnames/templates/records.template.yaml
+++ /dev/null
@@ -1,28 +0,0 @@
----
-dns_records_add:
- - view: private
- zone: {{ dns_domain }}
- entries:
-{% for mst in groups['masters'] %}
- - type: A
- hostname: {{ hostvars[mst]['ansible_hostname'] }}
- ip: {{ hostvars[mst]['dns_private_ip'] }}
-{% endfor %}
-{% for node in groups['nodes'] %}
- - type: A
- hostname: {{ hostvars[node]['ansible_hostname'] }}
- ip: {{ hostvars[node]['dns_private_ip'] }}
-{% endfor %}
- - view: public
- zone: {{ dns_domain}}
- entries:
-{% for mst in groups['masters']%}
- - type: A
- hostname: {{ hostvars[mst]['ansible_hostname'] }}
- ip: {{ hostvars[mst]['dns_public_ip'] }}
-{% endfor %}
-{% for node in groups['nodes'] %}
- - type: A
- hostname: {{ hostvars[node]['ansible_hostname'] }}
- ip: {{ hostvars[node]['dns_public_ip'] }}
-{% endfor %}