diff --git a/playbooks/bootstrap/roles/hostname/tasks/main.yaml b/playbooks/bootstrap/roles/hostname/tasks/main.yaml new file mode 100644 index 0000000..468499e --- /dev/null +++ b/playbooks/bootstrap/roles/hostname/tasks/main.yaml @@ -0,0 +1,24 @@ +# Copyright 2019 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- name: Set system hostname + become: true + hostname: + name: "{{ inventory_hostname.split('.', 1)[0] }}" + +- name: Create /etc/hosts + become: true + template: + dest: /etc/hosts + src: etc/hosts.j2 diff --git a/playbooks/bootstrap/site.yaml b/playbooks/bootstrap/site.yaml index d10a2b7..d509d59 100644 --- a/playbooks/bootstrap/site.yaml +++ b/playbooks/bootstrap/site.yaml @@ -28,6 +28,10 @@ include_role: name: users + - name: Setup hostname role + include_role: + name: hostname + - name: Setup swap role include_role: name: swap diff --git a/playbooks/bootstrap/templates/etc/hosts.j2 b/playbooks/bootstrap/templates/etc/hosts.j2 new file mode 100644 index 0000000..a8d6c5d --- /dev/null +++ b/playbooks/bootstrap/templates/etc/hosts.j2 @@ -0,0 +1,5 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +# +127.0.0.1 localhost +{{ hostvars[inventory_hostname].ansible_host }} {{ inventory_hostname }} {{ inventory_hostname.split('.', 1)[0] }}