ansibleplaybookbundle / hello-world-apb

An APB which deploys a sample Hello World! application
3 stars 10 forks source link

Modernized Hello-World APB #3

Closed djzager closed 6 years ago

djzager commented 6 years ago

I'm playing around/investigating with a "modernized" APB example. The end goal is to have something showing off openshift_raw and k8s_raw as well as a functioning test playbook. Right now though I've restructured this APB into a single role and wanted to get feedback before moving any further.

djzager commented 6 years ago

Example runthrough with multiple provisions in same namespace:

Provision apb with apb_id=2

(apb) ➜  hello-world-apb git:(apb-ref-example) ✗ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb provision --extra-vars 'apb_id=2'
+ [[ provision --extra-vars apb_id=2 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=provision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/provision.yaml ]]
+ [[ -e /opt/apb/actions/provision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/provision.yml --extra-vars apb_id=2

PLAY [hello-world-apb provision] ***********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

Provision apb with apb_id=1

$  hello-world-apb git:(apb-ref-example) ✗ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb provision --extra-vars 'apb_id=1'
+ [[ provision --extra-vars apb_id=1 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=provision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/provision.yaml ]]
+ [[ -e /opt/apb/actions/provision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/provision.yml --extra-vars apb_id=1

PLAY [hello-world-apb provision] ***********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

See all in the namespace

$ oc get all -n hello-world
NAME                                                                 REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfigs/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   1          1         0         config
deploymentconfigs/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   1          1         0         config

NAME                                                      HOST/PORT                                                                        PATH      SERVICES                                           PORT      TERMINATION   WILDCARD
routes/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-hello-world.172.17.0.1.nip.io             hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   web                     None
routes/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-hello-world.172.17.0.1.nip.io             hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   web                     None

NAME                                                           READY     STATUS    RESTARTS   AGE
po/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-1-deploy   0/1       Error     0          14s
po/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1-deploy   0/1       Error     0          8s

NAME                                                    DESIRED   CURRENT   READY     AGE
rc/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab-1   0         0         0         14s
rc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1   0         0         0         8s

NAME                                                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
svc/hello-world-5acebd43-ef18-5da4-9d08-543ae781fcab   ClusterIP   172.30.237.56    <none>        8080/TCP   13s
svc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   ClusterIP   172.30.221.152   <none>        8080/TCP   7s

Deprovision apb_id=2

$ docker run --rm --net=host -v $HOME/.kube:/opt/apb/.kube:z -u $UID hello-world-apb deprovision --extra-vars 'apb_id=2'
+ [[ deprovision --extra-vars apb_id=2 == *\s\2\i\/\a\s\s\e\m\b\l\e* ]]
+ ACTION=deprovision
+ shift
+ playbooks=/opt/apb/actions
+ CREDS=/var/tmp/bind-creds
+ TEST_RESULT=/var/tmp/test-result
+ whoami
+ '[' -w /etc/passwd ']'
++ id -u
+ echo 'apb:x:1000:0:apb user:/opt/apb:/sbin/nologin'
+ set +x
+ [[ -e /opt/apb/actions/deprovision.yaml ]]
+ [[ -e /opt/apb/actions/deprovision.yml ]]
+ ANSIBLE_ROLES_PATH=/etc/ansible/roles:/opt/ansible/roles
+ ansible-playbook /opt/apb/actions/deprovision.yml --extra-vars apb_id=2

PLAY [hello-world-apb deprovision] *********************************************

TASK [hello-world-apb : deployment config] *************************************
changed: [localhost]

TASK [hello-world-apb : hello-world service] ***********************************
changed: [localhost]

TASK [hello-world-apb : create hello-world route] ******************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=3    changed=3    unreachable=0    failed=0

+ EXIT_CODE=0
+ set +ex
+ '[' -f /var/tmp/test-result ']'
+ exit 0

See if apb_id=1 survived

$ oc get all -n hello-world
NAME                                                                 REVISION   DESIRED   CURRENT   TRIGGERED BY
deploymentconfigs/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   1          1         0         config

NAME                                                      HOST/PORT                                                                        PATH      SERVICES                                           PORT      TERMINATION   WILDCARD
routes/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-hello-world.172.17.0.1.nip.io             hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   web                     None

NAME                                                           READY     STATUS    RESTARTS   AGE
po/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1-deploy   0/1       Error     0          6m

NAME                                                    DESIRED   CURRENT   READY     AGE
rc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676-1   0         0         0         6m

NAME                                                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
svc/hello-world-dae097b5-4296-5d3f-8cc4-4acee86b3676   ClusterIP   172.30.221.152   <none>        8080/TCP   6m
LorbusChris commented 6 years ago

@djzager I'm liking the simplified structure!

Here's an idea of what it could look like to add per-container config-roles (aka container-enabled) to the APB: https://github.com/djzager/Hello-World-APB/pull/1

LorbusChris commented 6 years ago

Maybe the container name shouldn't be the same as the pod's name, in case there's multiple containers deployed to the pod and we want to easily differentiate them?

dymurray commented 6 years ago

Any ideas why deprovision is failing?

jwmatthews commented 6 years ago

@djzager what are next steps with this PR?

djzager commented 6 years ago

@jwmatthews The next steps are:

  1. Figure out what to do with the test playbook. If you look at the mariadb-apb HA PR, specifically the test playbook there are some good things going on there that we should investigate. It goes beyond the typical "verifications" that I've seen in other test playbooks and actually interacts with the database as a test. It's also a little complex. I want to be sure that test playbooks are supported by any apb-test-shim we develop. There may be nothing more to do here as the apb-test-shim already runs the test playbook if it exists in the project.
  2. Talk with @dymurray and make sure that what I'm doing here lines up with the ansible-galaxy integration.
  3. Move the apb-test-shim project under one of our organizations.
djzager commented 6 years ago

I'm using this PR to test the changes in --> https://github.com/ansibleplaybookbundle/apb-test-shim/pull/4 In the end this will rely on that PR being merged.

djzager commented 6 years ago

@fabianvf + @dymurray I think this is ready to go

djzager commented 6 years ago

Updated the example to use lookups based on @fabianvf request. Now this is blocked by https://github.com/ansible/ansible/pull/37533 ... once that is merged I'll make sure everything is good to go and get :+1: again.

djzager commented 6 years ago

Putting this here for when I forget. The kubernetes latest is going to fail because of https://github.com/kubernetes/minikube/issues/2629