Skip to content
Snippets Groups Projects
Forked from uffd / uffd
Source project has a limited visibility.

docker_xtras role

This ansible-role for dealing with after the creation of the the docker images to fix/add extra tasks before starting the nedded containers.

At the moment, the tasks included are:

  • disable the CUPS service
  • set folders permissions, because sometimes, mounting a countainer folder, we need to fix it's permissions before running it.

Requirements

  • To have ansible installed at your system.

Configuration

You need to set some configuration for this to work

  • ansible.cfg

    You have to edit the ansible.cfg file to your needs for accessing your target.

    • remote_user

      You need to set the remote_user configuration for accessing the target host.

      Example: remote_user

  • HOST_VARS

    In order to access your target host, you need to create/edit your inventories/host_vars/<YOUR_HOST_NAME>.yml

    • ansible_become_pass

      You need to set the sudo password from the user setted on remote_user for installing packages and etc. at the target.

      Example: ansible_become_pass

  • HOSTS

    You need to provide a group in which your target belongs to with the same name setted for inventories/host_vars/<YOUR_HOST_NAME>.yml.

    There you can add/edit the target address/IP.

    Example: hosts

Role Variables

Here are the variables setted:

  • From CUPS service

    Here are the variables needed to disable the CUPS service at the target host.

    • c3infodesk_deployment_repository_dest_folder

      • This should be a string entry with the path of the folder where is located the folder from the project that you are using this role to fix things before starting the container.
      • This variable is also needed for setting the clone-repository role.
      • DEFAULT: "/tmp/test"
    • c3infodesk_deployment_docker_xtras_cups_disable

      • This should be a boolean entry with the value from if you want or not to disable the CUPS service at the target host.
      • DEFAULT: false
    • c3infodesk_deployment_docker_xtras_cups_mask

      • This should be a boolean entry with the value from if you want or not to mask the CUPS service at the target host.
      • DEFAULT: false
    • c3infodesk_deployment_docker_xtras_cups_disable_debug

      • This should be a boolean entry with the value from if you want or not to see the debug outputs from setting the CUPS at the target host.
      • DEFAULT: false
  • From setting the folders permissions

    Here are the variables needed to change/update the folders permissions.

    • c3infodesk_deployment_docker_xtras_fix_folders_permissions

      • This should be a boolean entry with the value from if you want or not to fix folder permissions at the target host.
      • DEFAULT: false
    • c3infodesk_deployment_docker_xtras_fix_folders_permissions_debug

      • This should be a boolean entry with the value from if you want or not to see the debug outputs from setting the folders permissions at the target host.
      • DEFAULT: false
    • c3infodesk_deployment_docker_xtras_fix_folders_permissions_list

      • This should be a list entry with the the information of the folders that needes to be have new permissions setted.
      • This list include entries with the default keys:
        • folder_path
          • The path from the location of the docker mounted folder that needs new permissions.
        • folder_mode
          • This should be an octal entry with the mode from the folder to be updated The mode that .
      • DEFAULT: The default values are seeted for the c3buttons project.
        c3infodesk_deployment_docker_xtras_fix_folders_permissions_list:
          - folder_path: docker/grafana/data
            folder_mode: "0777"

Dependencies

The role dependencies are:

Example Playbook

  • Using the provided example

    For using the example playbook playbooks/examples/example_04_docker_images.yml file you only need to:

    And run the command:

    ansible-playbook -i inventories/hosts playbooks/examples/example_04_docker_images.yml
  • Setting your own example

    After setting your variables at inventories/host_vars/<HOST_NAME>, you can add this role to your playbook as a regular role.

    Here is an example using the <HOST_NAME> as test_servers

    - hosts:
        - test_servers
      roles:
        - roles/c3infodesk-deployment-role-docker-xtras

    And call the playbook as:

    ansible-playbook -i <INVENTORY> <PLAYBOOK_NAME>.yml

Testing

You can test this locally using DIND (docker in docker) at your own computer using ansible molecule

  • Testing requirements

    You need docker installed at your system and the ansible molecule.

    • Setting DIND (docker in docker)

      You might have to set DIND (docker in docker) at your system, for linux, you can create the file /etc/docker/daemon.json

      • Enabling DIND at your system

        And add the content and restart docker.

        {
          "exec-opts": ["native.cgroupdriver=systemd"],
          "features": {
            "buildkit": true
          },
          "experimental": true,
          "cgroup-parent": "docker.slice"
        }
  • Using the molecule tests

    • Configuring the HOST_VAR_FILE_NAME variable

      For using the molecule tests you should pass the HOST_VAR_FILE_NAME environment variable, or the default value for testing is: example_printer.yml

      For the values that can be used, you can lool at the files at the inventories/host_vars folder.

      • Molecule test example
        Just go to the root of the role roles/x3infodesk-deployment-role-dependencies and run the command, here is an example for using the HOST_VAR_FILE_NAME as example_buttons.yml:
        HOST_VAR_FILE_NAME="example_buttons.yml" molecule test

License

MIT / BSD

Author Information

https://chaos.social/@fejao