From 3866232daed8ce1a48aa2db6f2f6c541e90756ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Bedin?= Date: Fri, 17 Jun 2016 14:48:37 -0400 Subject: Cleande up hostname role to make it more generic --- roles/hostnames/tasks/main.yaml | 43 ++++++++++++------------- roles/hostnames/templates/records.template.yaml | 28 ---------------- 2 files changed, 21 insertions(+), 50 deletions(-) delete mode 100644 roles/hostnames/templates/records.template.yaml (limited to 'roles') 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 %} -- cgit v1.2.3