Skip to content

Commit

Permalink
Fix container hostname for RFC 1034/1035
Browse files Browse the repository at this point in the history
In lxc-container create this update will ensure we're using good
hostnames. This is required in some logging cases as well as SSL.
This will also allow a deployer to customize the domain name based on
their needs.

A new variable has been created called ``lxc_container_domain`` with a
default value of "openstack.local". This change has no upgrade impact as
any changes that need to happen within an existing environment will be
automatically taken care of without impacting the functionality of an
existing deployment.

This is largely based on Ib31a48dd480ecb376a6a8c5b35b09dfa5d2e58f6, with
the intent being to move the tasks from a playbook in the integrated
repo to the lxc_container_create role, and with the addition of limiting
127.0.0.1 to localhost within /etc/hosts.

Change-Id: I9e72699354a467478742281cab74690e66b6a652
Co-Authored-By: Kevin Carter <kevin.carter@rackspace.com>
  • Loading branch information
jimmymccrory and cloudnull committed May 7, 2016
1 parent b92f1c0 commit ccddfc7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
2 changes: 2 additions & 0 deletions defaults/main.yml
Expand Up @@ -31,6 +31,8 @@ lxc_container_vg_name: lxc

lxc_container_default_mtu: "1500"

lxc_container_domain: "openstack.local"

# LXC image server
lxc_image_cache_server: images.linuxcontainers.org

Expand Down
@@ -0,0 +1,15 @@
---
features:
- LXC containers will now have a proper RFC1034/5 hostname set during post
build tasks. A localhost entry for 127.0.1.1 will be created by converting
all of the "_" in the ``inventory_hostname`` to "-". Containers will be
created with a default domain of *openstack.local*.
This domain name can be customized to meet your deployment needs by
setting the option ``lxc_container_domain``.
upgrade:
- LXC containers will now have a proper RFC1034/5 hostname set during post
build tasks. A localhost entry for 127.0.1.1 will be created by converting
all of the "_" in the ``inventory_hostname`` to "-". Containers will be
created with a default domain of *openstack.local*.
This domain name can be customized to meet your deployment needs by
setting the option ``lxc_container_domain``.
41 changes: 41 additions & 0 deletions tasks/container_create.yml
Expand Up @@ -190,3 +190,44 @@
- global_environment_variables is defined
tags:
- lxc-container-proxy

- name: Create localhost config
lineinfile:
dest: "/etc/hosts"
regexp: "^127.0.0.1"
line: "127.0.0.1 localhost"
owner: "root"
group: "root"
mode: "0644"
remote_user: root
tags:
- lxc-container-hostname

- name: Create domain config
lineinfile:
dest: "/etc/hosts"
regexp: "^127.0.1.1"
line: "127.0.1.1 {{ inventory_hostname | replace('_', '-') }}.{{ lxc_container_domain }} {{ inventory_hostname | replace('_', '-') }}"
owner: "root"
group: "root"
mode: "0644"
remote_user: root
tags:
- lxc-container-hostname

- name: Create hostname
copy:
dest: "/etc/hostname"
content: "{{ inventory_hostname | replace('_', '-') }}"
owner: "root"
group: "root"
mode: "0644"
remote_user: root
tags:
- lxc-container-hostname

- name: Setup hostname
command: hostname -F /etc/hostname
remote_user: root
tags:
- lxc-container-hostname

0 comments on commit ccddfc7

Please sign in to comment.