Skip to content

Instantly share code, notes, and snippets.

@sayan3296
Last active December 31, 2022 11:04
Show Gist options
  • Save sayan3296/da690f8891cdd486d9a1ea4536a37cee to your computer and use it in GitHub Desktop.
Save sayan3296/da690f8891cdd486d9a1ea4536a37cee to your computer and use it in GitHub Desktop.
satellite-fqdn host entry missing from Foreman - breakfix
Requirements:
* Satellite 6.11 ( latest minor release ) installed on RHEL 7 or RHEL 8
* Organization RedHat and Location GSS
* No contents\repo\manifest required
Breakfix Playbook:
~~~
---
- name: Creating breakfix for "Host does not exist in Foreman" in Satellite 6.11
hosts: psi_satellite_611
gather_facts: true
vars:
organization: RedHat
tasks:
- name: Ensure the /etc/hosts file have correct entry for satellite
replace:
path: /etc/hosts
regexp: "{{ item.source }}"
replace: "{{ item.replace }}"
loop:
- { source: "{{ ansible_hostname }} {{ ansible_fqdn }}", replace: "{{ ansible_fqdn }} {{ ansible_hostname }}" }
- name: Check the presence of ssl-build directory.
stat:
path: "/root/ssl-build"
register: ssl_build
- name: Create the ssl-build directory is it was not present.
file:
path: /root/ssl-build
state: directory
mode: '0755'
when: ssl_build is defined and not ssl_build.stat.exists
- name: Run installer to generate certs into ssl-build directory.
command: bash -c "satellite-installer -S satellite"
when: ssl_build is defined and not ssl_build.stat.exists
- name: Modify few settings of Satellite server.
command: bash -c "hammer settings set --name {{ item.name }} --value {{ item.value }}"
loop:
- { name: "append_domain_name_for_hosts", value: "false" }
- { name: "create_new_host_when_facts_are_uploaded", value: "false" }
- { name: "create_new_host_when_report_is_uploaded", value: "false" }
- { name: "use_shortname_for_vms", value: "true" }
register: settings_updated
- name: Change FQDN to shortname
hostname:
name: "{{ ansible_hostname }}"
register: hostname_changed
when: settings_updated is success
- name: Find out the information about current host record.
command: bash -c "hammer --no-headers host list --fields Name"
register: current_name
- name: Update the host record in database for satellite
command: >
bash -c "hammer host update --name {{ ansible_fqdn }} --new-name {{ ansible_hostname }} --organization {{ organization }}"
register: record_updated
when: hostname_changed is success and current_name.stdout != ansible_hostname
- name: Run installer to confirm that it broke
command: bash -c "satellite-installer -S satellite"
register: installer
when: current_name.stdout != ansible_hostname
failed_when: '"does not exist in Foreman" not in installer.stdout'
- name: Modify the /etc/hosts file
replace:
path: /etc/hosts
regexp: "{{ item.source }}"
replace: "{{ item.replace }}"
loop:
- { source: "{{ ansible_fqdn }} {{ ansible_hostname }}", replace: "{{ ansible_hostname }} {{ ansible_fqdn }}" }
register: hostfile_updated
~~~
Issue: satellite-installer execution is failing ( either with DNS error or with host does not exists error )
Task:
* Ensure that satellite-installer executed successfully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment