Skip to content

Commit

Permalink
New Role (#8930)
Browse files Browse the repository at this point in the history
* New role

* update

* update

* update

* adding become block
  • Loading branch information
miteshget authored Dec 16, 2024
1 parent a15abee commit 93b93e9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions ansible/roles/set_host_public_fqdn/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= Set Host Public FQDN for Nodes
15 changes: 15 additions & 0 deletions ansible/roles/set_host_public_fqdn/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

# Public Domain name
set_host_public_fqdn_domain_name: "{{ guid }}{{ subdomain_base_suffix }}"

# List of host/nodes
set_host_public_fqdn_host_list: "{{ groups['nodes'] }}"

# Examples:
# set_host_public_fqdn_host_list:
# - "{{ groups['nodes'] }}"
# - node1
# - node2
# - "{{ groups['controllers'] }}"
# - "{{ groups['servers'] }}"
8 changes: 8 additions & 0 deletions ansible/roles/set_host_public_fqdn/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
galaxy_info:
author: Mitesh The Mouse
description: Set public hostname for nodes useful for insights and satellite clients
company: Red Hat
version: 1.0.0
license: license (GPL-3.0)
min_ansible_version: 2.14
7 changes: 7 additions & 0 deletions ansible/roles/set_host_public_fqdn/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Include set_fqdn for hosts
ansible.builtin.include_tasks:
file: set_fqdn.yml
loop: "{{ set_host_public_fqdn_host_list }}"
loop_control:
loop_var: _host
26 changes: 26 additions & 0 deletions ansible/roles/set_host_public_fqdn/tasks/set_fqdn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Extract hostname
ansible.builtin.set_fact:
_hostname: "{{ _host.split('.')[0] }}"
delegate_to: "{{ _host }}"

- name: Create public fqdn
ansible.builtin.set_fact:
_host_public_fqdn: "{{ _hostname + '.' + set_host_public_fqdn_domain_name }}"
delegate_to: "{{ _host }}"

- name: Configure Public FQDN
become: true
block:
- name: Set host public fqdn
ansible.builtin.hostname:
name: "{{ _host_public_fqdn }}"
delegate_to: "{{ _host }}"

- name: Configure public fqdn in hosts file
ansible.builtin.lineinfile:
dest: /etc/hosts
state: present
insertafter: EOF
line: "{{ ansible_default_ipv4['address'] }} {{ _host_public_fqdn }}"
delegate_to: "{{ _host }}"

0 comments on commit 93b93e9

Please sign in to comment.