Skip to content
Snippets Groups Projects
Verified Commit 839da697 authored by Maarten de Waard's avatar Maarten de Waard :angel:
Browse files

remove settings.yml from the mix

parent ddfe9231
No related branches found
No related tags found
No related merge requests found
---
# Directory to store generated configuration and cluster state.
data_directory: "/var/lib/OpenAppStack"
ip_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
# Use python3 on cluster nodes for ansible
ansible_python_interpreter: "/usr/bin/env python3"
......
# External ip address of the cluster.
ip_address: "203.0.113.6"
# Main domain name of the cluster services.
domain: "example.com"
# It is possible to add a docker mirror that serves images from docker.io.
docker_mirror:
enabled: false
# endpoint: URL of docker mirror
# username: username for auth
# password: password for auth
......@@ -11,12 +11,3 @@
that: "cluster_dir is defined"
msg: >
"Please define the variable `cluster_dir`."
- name: Check if all variables from settings.yml.example are set in your settings.yml file
assert:
that: "{{ item }} is defined"
msg: >
"Please define the variable `{{ item }}`."
with_items:
- ip_address
- domain
......@@ -354,7 +354,7 @@ def create(clus, args): # pylint: disable=too-many-branches
if args.docker_mirror_password:
clus.docker_mirror_password = args.docker_mirror_password
# Write inventory.yml and settings.yml files
# Write inventory.yml
clus.write_cluster_files()
if args.create_domain_records:
......
......@@ -56,7 +56,7 @@ class Cluster:
self.domain = None
# Set this to False if the data needs to be (re)loaded from file
self.data_loaded = False
# Load data from inventory.yml and settings.yml
# Load data from inventory.yml
if load_data:
self.load_data()
# Can be used to use a custom disk image.
......@@ -68,28 +68,23 @@ class Cluster:
def load_data(self):
"""
Loads cluster data from inventory.yml and settings.yml files
Loads cluster data from inventory.yml and files
Set self.data_loaded to False if this function should re-read data
from file.
"""
if not self.data_loaded:
with open(self.settings_file, 'r') as stream:
settings = yaml.safe_load(stream)
self.ip_address = settings['ip_address']
self.domain = settings['domain']
log.debug("""Read data from settings.yml:
ip address: %s
domain: %s""", self.ip_address, self.domain)
with open(self.inventory_file, 'r') as stream:
inventory = yaml.safe_load(stream)
# Work with the master node from the inventory
self.hostname = inventory['all']['children']['master']['hosts']
log.debug(
'Read data from inventory.yml:\n\thostname: %s', self.hostname)
self.domain = self.hostname
self.ip_address = \
inventory['hosts'][self.hostname]['ansible_host']
log.debug("""Read data from inventory:
ip address: %s
domain: %s
hostname: %s""", self.ip_address, self.domain, self.hostname)
else:
log.debug('Not loading cluster data from file. Set '
'Cluster.data_loaded to False if you want a reload.')
......@@ -157,41 +152,9 @@ class Cluster:
self.hostname = hostname
def write_cluster_files(self):
"""Creates an inventory.yml and settings.yml file for the cluster"""
"""Creates an inventory.yml and dotenv file for the cluster"""
self.make_cluster_directories()
ansible.create_inventory(self)
# Create settings
with open(os.path.join(ansible.ANSIBLE_PATH, 'group_vars',
'all', 'settings.yml.example'),
'r') as stream:
settings = yaml.safe_load(stream)
settings['ip_address'] = self.ip_address
settings['domain'] = self.domain
settings['cluster_dir'] = self.cluster_dir
if self.docker_mirror_endpoint \
and self.docker_mirror_server \
and self.docker_mirror_username \
and self.docker_mirror_password:
settings['docker_mirror']['enabled'] = True
settings['docker_mirror']['endpoint'] = self.docker_mirror_endpoint
settings['docker_mirror']['username'] = self.docker_mirror_username
settings['docker_mirror']['password'] = self.docker_mirror_password
settings['docker_mirror']['server'] = self.docker_mirror_server
file_contents = yaml.safe_dump(settings, default_flow_style=False)
log.debug(file_contents)
# Create CLUSTER_DIR/group_vars/all/ if non-existent
vars_dir = os.path.dirname(self.settings_file)
if not os.path.exists(vars_dir):
os.makedirs(vars_dir)
with open(self.settings_file, 'w') as stream:
stream.write(file_contents)
log.info("Created %s", self.settings_file)
dotenv_file = """CLUSTER_NAME={name}
CLUSTER_DIR={cluster_dir}
IP_ADDRESS={ip_address}
......@@ -225,12 +188,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
"""Path to the ansible inventory.yml for this cluster"""
return os.path.join(self.cluster_dir, 'inventory.yml')
@property
def settings_file(self):
"""Path to the ansible settings.yml for this cluster"""
return os.path.join(self.cluster_dir, 'group_vars', 'all',
'settings.yml')
@property
def dotenv_file(self):
"""Path to the .cluster.env file with relevant environment variables"""
......@@ -328,7 +285,6 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
Configuration:
- Inventory file: {inventory_file}
- Settings file: {settings_file}
Kubectl:
......@@ -341,5 +297,4 @@ KUBECONFIG={secret_dir}/kube_config_cluster.yml
hostname=self.hostname,
domain=self.domain,
inventory_file=self.inventory_file,
settings_file=self.settings_file,
secret_dir=self.secret_dir))
......@@ -121,8 +121,8 @@ def test_cert_validation(host, app): # pylint: disable=too-many-statements
print("Using domain %s from FQDN environment variable." % domain)
else:
ansible_vars = host.ansible.get_variables()
domain = ansible_vars["domain"]
print("Using domain %s from ansible settings.yml." % domain)
domain = ansible_vars["inventory_hostname"]
print("Using domain %s from ansible inventory." % domain)
add_custom_cert_authorities(certifi.where(),
['pytest/le-staging-bundle.pem'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment