# Prepare ansible Installation

## Install needed python pip packages

    pip3 install -r pip-requirements

## Install needed ansible collections / roles

    ansible-galaxy install -r galaxy-requirements.yml

# Setup
Create/Start servers for stage-dev

    ansible-playbook -i stage-dev provisioning.yml --vault-password-file ~/vault-pass
    ansible-playbook -i stage-dev start.yml --vault-password-file ~/vault-pass
    ansible-playbook -i stage-dev stop.yml --vault-password-file ~/vault-pass

> with Poetry prefix with `poetry run`

# Provisioning

    ansible-playbook -i stage-dev setup.yml --vault-password-file ~/vault-pass -u root
    ansible-playbook dynamic-provisioning.yml  --vault-password-file ~/vault-pass -e "stage=dev name=test node=01 service=connect"

> with Poetry prefix with `poetry run`

# Setup Smardigo Service
    Setup/Configure a Server, Database, Realm (keycloak) and Smardigo
    ansible-playbook create-server.yml -e "stage='dev' tenant_id='sken' cluster_name='test01' cluster_size='1' cluster_service='connect' stage='dev'"
    ansible-playbook create-database.yml -e "stage='dev' tenant_id='sken' cluster_name='test01' cluster_size='1' cluster_service='connect' stage='dev'"
    ansible-playbook create-realm.yml -e "stage='dev' tenant_id='sken' cluster_name='test01' cluster_size='1' cluster_service='connect' stage='dev' current_realm_name='sken' current_realm_display_name='S-K-E-N'"
    ansible-playbook create-service.yml -e "stage='dev' tenant_id='sken' cluster_name='test01' cluster_size='1' cluster_service='connect' stage='dev' current_realm_name='sken' current_realm_display_name='S-K-E-N'"

> with Poetry prefix with `poetry run`

# Remove Smardigo Service
	Remove a Server, Database, Realm (keycloak) and Smardigo
	ansible-playbook remove-server.yml -e "stage='dev' tenant_id='sken' cluster_name='test01' cluster_size='1' cluster_service='connect' stage='dev'"


> with Poetry prefix with `poetry run`

# ansible-builder
[AWX](https://www.ansible.com/products/awx-project/) is used in smardigo setup do execute several playbooks due to user interaction within smardigo product. To finish ansible runs successfully we have to make sure every ansible dependency(ansible collection/role or pip package) is installed. therefore ansible-builder gave us the opportunity to configure the needed environment to exec plays successfully. 

before every git-merge depending on changes concerning new ansible collections/roles and/or new pip-packages, please run the following:

    cd ansible-builder/
    ansible-builder build --tag dev-harbor-01.smardigo.digital/awx/awx-custom-ee --container-runtime docker



hopefully it will result in e.g.:

    cd ansible-builder/
    ATTENTION: to get more information plz set --verbosity 3	
    ansible-builder build --tag awx-custom-ee:latest --container-runtime docker
    Running command:
      docker build -f context/Dockerfile -t awx-custom-ee:latest context
    
    Complete! The build context can be found at: /home/friedrich/sandbox/netgo_stuff/hetzner-ansible/ansible-builder/context
    
    real	2m56,131s
    user	0m0,208s
    sys	0m0,102s`
 
you can start the docker container locally with e.g. :
    docker run -it --rm --mount type=bind,source="$(pwd)"/,target=/gitrepo/   awx-custom-ee:latest /bin/bash


after it, you are able to exec some ansbible-runs like:
(please solve dependencies before starting to docker container)
    cd /gitrepo
    ansible-playbook -i stage-digitalocean external_monitoring.yml --ask-vault-password -u root --private-key sshkey_pw_less 
    
    export HETZNER_LABEL_SELECTOR='stage=dev'
    ansible-playbook -i stage-netgo-hcloud.yml -l redis smardigo.yml --ask-vault-password  -u root --private-key sshkey_pw_less
  

if everything works fine, plz push the created docker container with:

    docker login dev-harbor-01.smardigo.digital
    docker tag XXXXXXXX dev-harbor-01.smardigo.digital/awx/awx-custom-ee:latest
    docker push dev-harbor-01.smardigo.digital/awx/awx-custom-ee







# TODO

Prometheus (Grafana)
  docker exec -i dev-prometheus-01-grafana sh -c 'grafana-cli plugins install grafana-piechart-panel'
  docker restart dev-prometheus-01-grafana
