Changeset - d44e023cf7bb
[Not reviewed]
0 10 0
Branko Majic (branko) - 5 years ago 2020-10-01 22:17:16
branko@majic.rs
MAR-155: Make the preseed_directory parameter in the preseed role mandatory:

- Updated the preseed role.
- Removed default value for the parameter.
- Updated tests.
- Updated role reference documentation.
- Updated release notes.
10 files changed with 14 insertions and 30 deletions:
0 comments (0 inline, 0 general)
docs/releasenotes.rst
Show inline comments
 
@@ -44,12 +44,16 @@ Breaking changes:
 

	
 
  * Updated default set of TLS ciphers used by IMAP/SMTP servers
 
    (``mail_server_tls_ciphers`` parameter). All CBC ciphers have been
 
    dropped. This could introduce incompatibility with older clients
 
    trying to connect to the IMAP/SMTP server.
 

	
 
* ``preseed`` role
 

	
 
  * Parameter ``preseed_directory`` is now mandatory.
 

	
 
* ``web_server`` role
 

	
 
  * Use 2048-bit Diffie-Hellman parameters for relevant TLS
 
    ciphers. This could introduce incompatibility with older clients
 
    trying to connect to the web server.
 

	
docs/rolereference.rst
Show inline comments
 
@@ -46,13 +46,13 @@ Parameters
 
  operating system user ``root``. This is necessary for the bootstrap process
 
  to work since Debian does not allow password-based logins for root.
 

	
 
**preseed_country** (string, optional, ``SE``)
 
  Country.
 

	
 
**preseed_directory** (string, optional, ``../preseed_files/``)
 
**preseed_directory** (string, mandatory)
 
  Destination directory where the preseed files should be stored.
 

	
 
  .. warning::
 
     Do not name this directory ``preseed`` if it lies on a path where Ansible
 
     would normally look-up the roles (it will conflict with the role name).
 

	
roles/preseed/defaults/main.yml
Show inline comments
 
---
 

	
 
ansible_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
 
preseed_country: SE
 
preseed_directory: "{{ inventory_dir }}/preseed_files"
 
preseed_keymap: us
 
preseed_language: en
 
preseed_locale: en_US.UTF-8
 
preseed_mirror_directory: /debian
 
preseed_mirror_hostname: ftp.se.debian.org
 
preseed_mirror_proxy: ""
roles/preseed/molecule/default/group_vars/parameters-mandatory.yml
Show inline comments
 
---
 

	
 
preseed_directory: "/tmp/preseed_files/"
roles/preseed/molecule/default/group_vars/parameters-optional-with-overrides.yml
Show inline comments
 
---
 

	
 
preseed_directory: /tmp/custom_preseed_files_location
 
ansible_key: CUSTOMKEY
 
preseed_directory: "/tmp/preseed_files/"
 
preseed_server_overrides:
 
  parameters-optional-with-overrides-stretch64:
 
    country: RS
 
    dns: 1.1.1.1
 
    domain: example.com
 
    gateway: 2.2.2.2
roles/preseed/molecule/default/group_vars/parameters-optional.yml
Show inline comments
 
---
 

	
 
ansible_key: CUSTOMKEY
 
preseed_country: RS
 
preseed_directory: /tmp/custom_preseed_files_location
 
preseed_directory: "/tmp/preseed_files/"
 
preseed_dns: 1.1.1.1
 
preseed_domain: example.com
 
preseed_gateway: 2.2.2.2
 
preseed_hostname: testing
 
preseed_ip: 3.3.3.3
 
preseed_keymap: sv
roles/preseed/molecule/default/prepare.yml
Show inline comments
 
@@ -5,20 +5,6 @@
 
  gather_facts: false
 
  tasks:
 
    - name: Install python for Ansible
 
      raw: test -e /usr/bin/python3 || (apt -y update && apt install -y python3-minimal)
 
      become: true
 
      changed_when: false
 

	
 
- hosts: parameters-mandatory
 
  become: true
 
  tasks:
 

	
 
    # @TODO: This is a hack because inventory_dir used for
 
    # preseed_directory comes from _host_.
 
    - name: Set-up inventory directory matching location where molecule is running itself
 
      file:
 
        path: "{{ inventory_dir }}"
 
        state: directory
 
        owner: vagrant
 
        group: vagrant
 
        mode: 0700
roles/preseed/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
import os
 
import pwd
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')
 
@@ -12,18 +11,13 @@ def test_preseed_directory(host):
 
    """
 
    Tests presence and permissions on created preseed directory.
 
    """
 

	
 
    with host.sudo():
 

	
 
        # Preseed directory created at same level as inventory.
 
        # @TODO: At this point, this path is getting uglier and
 
        #        uglier. It might be actually better to make the
 
        #        preseed_directory a mandatory parameter instead. Same
 
        #        goes for the ansible_key role parameter as well.
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 
        preseed_directory_path = "/tmp/preseed_files"
 
        preseed_directory = host.file(preseed_directory_path)
 

	
 
        assert preseed_directory.is_directory
 
        assert preseed_directory.mode == 0o750
 

	
 

	
 
@@ -31,14 +25,13 @@ def test_preseed_configuration_files(host):
 
    """
 
    Tests presence and permissions on created preseed configuration files.
 
    """
 

	
 
    with host.sudo():
 

	
 
        # Preseed directory created at same level as inventory.
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 
        preseed_directory_path = "/tmp/preseed_files"
 

	
 
        # Verify that preseed configuration files are created for all hosts.
 
        for testinfra_host in testinfra_hosts:
 

	
 
            preseed_file = host.file(os.path.join(preseed_directory_path, "%s.cfg" % testinfra_host))
 

	
 
@@ -51,13 +44,13 @@ def test_preseed_configuration_file_content(host):
 
    Tests content of generated preseed configuration file.
 
    """
 

	
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 
        preseed_directory_path = "%s/.cache/molecule/preseed/default/inventory/preseed_files" % pwd.getpwuid(os.getuid()).pw_dir
 
        preseed_directory_path = "/tmp/preseed_files"
 
        preseed_file = host.file(os.path.join(preseed_directory_path, "%s.cfg" % hostname))
 
        preseed_file_content = preseed_file.content_string
 
        ssh_public_key = open(os.path.join(os.path.expanduser("~"), ".ssh", "id_rsa.pub")).read().strip()
 

	
 
    assert "d-i debian-installer/language string en" in preseed_file_content
 
    assert "d-i debian-installer/country string SE" in preseed_file_content
roles/preseed/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
@@ -4,13 +4,13 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional')
 

	
 

	
 
PRESEED_DIRECTORY = '/tmp/custom_preseed_files_location'
 
PRESEED_DIRECTORY = '/tmp/preseed_files'
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Test presence and permissions of preseed directory.
 
    """
roles/preseed/molecule/default/tests/test_parameters_optional_with_overrides.py
Show inline comments
 
@@ -4,13 +4,13 @@ import testinfra.utils.ansible_runner
 

	
 

	
 
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional-with-overrides')
 

	
 

	
 
PRESEED_DIRECTORY = '/tmp/custom_preseed_files_location'
 
PRESEED_DIRECTORY = '/tmp/preseed_files'
 

	
 

	
 
def test_preseed_directory(host):
 
    """
 
    Test presence and permissions of preseed directory.
 
    """
0 comments (0 inline, 0 general)