Search code examples
gitansiblegit-submodulescompositioncode-reuse

Is there an industry standard method for composition of deployable configurations using git submodules per role?


I'd like to build up complex deployments as compositions of smaller repositories.

For example, I might want to deploy and inventory management server as an oracle UIM install, which I'd like to build on roles that configure the server, install the jdk, install weblogic, set up a basic domain, then drop UIM on that stack.

I can create roles that do our standard configurations, that install the jdk, that install the weblogic binaries, that install a standardized domain configuration, etc, but certain things are always going to need tweaking and abstraction.

Is there a standard for setting up common variables to be used between them, such as {{ install_user }} or {{ DB_URL }}?

If not, does anyone have good suggestions to help keep design on track in the absence of a project manager?


Solution

  • I have really complex setup of about 10 microservices and they are using tons of common variables and for which I have created a separate role with the name common_vars and it has only two folder inside defaults and tasks, where defaults contains all the common variables and tasks has empty main.yml and I import this role as meta dependency to all my other services deployment roles to share the common variables.

    -- common_vars
    |   |-- defaults
    |   |   `-- main.yml
    |   `-- tasks
    |       `-- main.yml
    

    My defaults/main.yml look like this (minimal example, in reality it's really big):

    ---
    ENVIRONMENT: "dev"
    
    COMMON_BASE_DIR: "/mydir"
    COMMON_WEB_DIR: "{{ COMMON_BASE_DIR }}/www"
    
    COMMON_LOG_DIR: "/var/log"
    
    COMMON_WEB_USER: "www-data"
    COMMON_WEB_GROUP: "www-data"
    
    
    common_ubuntu_packages:
      - git
      - vim
      - screen
    

    In my other roles meta/main.yml I add it as dependency like this:

    ---
    dependencies:
      - common_vars