c49153f8b2c205769c2c8dfba3d149fae8c46d1a
[demo.git] / tutorials / vFWDT / playbooks / configure_ansible.sh
1 #!/bin/bash
2
3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2019 Orange
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # ============LICENSE_END=========================================================
19
20 if [ ! -f playbooks/onap.pem ]; then
21         echo "onap.pem file does not exist"
22         exit
23 fi
24
25 K8S_NODE_IP=`kubectl get nodes -o=wide | grep 01 |  awk {'print $6'}`
26
27 CDT_REQ_DIR="workflow/templates/cdt-requests"
28
29 echo "APPC Artifacts configuration"
30
31 for f in $CDT_REQ_DIR/*.json; do
32         echo ""
33         echo "Uploading $f"
34         RES=`curl -k -s -X POST -H "Content-Type: application/json" -d @$f  https://$K8S_NODE_IP:30211/cdtService/getDesigns`
35         echo "$RES"
36
37         if [[ $RES != *'"code":"400","message":"success"'* ]]; then
38                 echo "CDT Artifact Upload failed"
39                 exit
40         fi
41 done
42
43 echo "APPC Artifacts configuration completed"
44
45 echo "APPC Ansible configuration"
46
47 ANSIBLE=`kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep appc-ansible`
48 echo $ANSIBLE
49
50 kubectl cp playbooks/onap.pem onap/$ANSIBLE:/opt/ansible-server/Playbooks/
51 echo "Key file uploaded"
52
53 cp workflow/Ansible_inventory playbooks/
54 kubectl cp playbooks/Ansible_inventory onap/$ANSIBLE:/opt/ansible-server/Playbooks/
55 echo "Ansible_inventory file uploaded"
56
57 kubectl exec -n onap $ANSIBLE -- chmod 400 /opt/ansible-server/Playbooks/onap.pem 
58 echo "Key file configured"
59
60 #kubectl exec -n onap $ANSIBLE -- sed -i 's#\(private_key_file *= *\).*#\1/opt/ansible-server/Playbooks/onap.pem#'  /etc/ansible/ansible.cfg
61 printf '[defaults]\nhost_key_checking = False\nprivate_key_file = /opt/ansible-server/Playbooks/onap.pem\n' > playbooks/ansible.cfg
62 kubectl cp playbooks/ansible.cfg onap/$ANSIBLE:/etc/ansible/
63 echo "Ansible conf modified"
64
65 kubectl exec -n onap $ANSIBLE -- ansible -i /opt/ansible-server/Playbooks/Ansible_inventory vpgn,vfw-sink -m ping
66 echo "Hosts PING test completed"
67
68 sudo kubectl cp playbooks/vfw-sink onap/$ANSIBLE:/opt/ansible-server/Playbooks/
69 echo "vFW-SINK Playbooks uploaded"
70
71 sudo kubectl cp playbooks/vpgn onap/$ANSIBLE:/opt/ansible-server/Playbooks/
72 echo "vPGN Playbooks uploaded"
73
74 APPCDB=`kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | grep appc-db-0`
75 echo $APPCDB
76
77 kubectl exec -n onap $APPCDB -- mysql -u sdnctl -pgamma sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
78 kubectl exec -n onap $APPCDB -- mysql -u sdnctl -pgamma sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET URL = "http://appc-ansible-server:8000/Dispatch" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
79 kubectl exec -n onap $APPCDB -- mysql -u sdnctl -pgamma sdnctl -e'UPDATE DEVICE_AUTHENTICATION SET PASSWORD = "admin" WHERE PROTOCOL LIKE "ANSIBLE" AND PASSWORD IS NULL;'
80 kubectl exec -n onap $APPCDB -- mysql -u sdnctl -pgamma sdnctl -e'SELECT * FROM DEVICE_AUTHENTICATION WHERE PROTOCOL LIKE "ANSIBLE";'
81 echo "APPC database configured for LCM commands"