<commit_before>{% if grains['os_family'] == 'Debian' %}
    {% set hostname_service = 'hostname' %}
{% elif grains['os_family'] == 'RedHat' %}
    {% set hostname_service = 'network' %}
{% endif %}


# Edit the appropriate hostname file
{% if grains['os_family'] == 'Debian' %}
hostname_file:
  file:
    - sed
    - user: root
    - name: /etc/hostname
    - order: 1
    - before: "^.*$"
    - after: "{{ grains['fqdn'] }}"
{% elif grains['os_family'] == 'RedHat' %}
hostname_file:
  file:
    - sed
    - user: root
    - name: /etc/sysconfig/network
    - order: 1
    - before: "^HOSTNAME=.*$"
    - after: "HOSTNAME={{ grains['fqdn'] }}"
{% endif %}

# Add an IP->FQDN mapping for each machine in the stack
stack_hostnames:
  file:
    - managed
    - user: root
    - group: root
    - mode: 644
    - name: /etc/hosts
    - template: jinja
    - source: salt://core/etc/hosts
    - require:
      - file: hostname_file

# Set the hostname of the machine based on the FQDN defined in a grain
set_hostname:
  cmd:
    - run
    - order: 1
    - user: root
    - name: "hostname {{ grains['fqdn'] }}"
    - unless: "hostname | grep {{ grains['fqdn'] }}"
    - require:
      - file: stack_hostnames

# Restart the apropriate service for this change to take effect
restart_hostname:
  cmd:
    - run
    - user: root
    - name: "service {{ hostname_service }} restart"
    - require:
      - cmd: set_hostname<commit_msg>Use service.running instead of cmd.run<commit_after>{% if grains['os_family'] == 'Debian' %}
    {% set hostname_service = 'hostname' %}
{% elif grains['os_family'] == 'RedHat' %}
    {% set hostname_service = 'network' %}
{% endif %}


# Edit the appropriate hostname file
hostname_file:
  file:
    - sed
    - user: root
{% if grains['os_family'] == 'Debian' %}
    - name: /etc/hostname
    - before: "^.*$"
    - after: "{{ grains['fqdn'] }}"
{% elif grains['os_family'] == 'RedHat' %}
    - name: /etc/sysconfig/network
    - before: "^HOSTNAME=.*$"
    - after: "HOSTNAME={{ grains['fqdn'] }}"
{% endif %}

# Add an IP->FQDN mapping for each machine in the stack
stack_hostnames:
  file:
    - managed
    - user: root
    - group: root
    - mode: 644
    - name: /etc/hosts
    - template: jinja
    - source: salt://core/etc/hosts

# Set the hostname of the machine based on the FQDN defined in a grain
set_hostname:
  cmd:
    - run
    - user: root
    - name: "hostname {{ grains['fqdn'] }}"
    - unless: "hostname | grep {{ grains['fqdn'] }}"
    - require:
      - file: hostname_file

# Restart the apropriate service for this change to take effect
hostname-svc:
  service:
    - running
    - name: {{ hostname_service }}
    - watch:
      - cmd: set_hostname
      - file: stack_hostnames
      - file: hostname_file
{'fraction_non_alphanumeric': 0.15713251267197684, 'fraction_numerical': 0.0032585083272990588, 'mean_word_length': 2.560567010309278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7249743', 'n_tokens_mistral': 1011, 'n_tokens_neox': 954, 'n_words': 255}