[feature/APPC-7] ansible server commit
[appc.git] / appc-adapters / appc-ansible-adapter / appc-ansible-example-server / README
1 '''
2 /*-
3 * ============LICENSE_START=======================================================
4 * APPC
5 * ================================================================================
6 * Copyright (C) 2017 AT&T Intellectual Property.  All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 */
22 '''
23
24 ============
25 INSTALLATION:
26 ============
27
28 Python:
29 -------
30 sudo apt-get install python2.7
31 sudo apt-get install python-pip
32 pip install PyMySQL
33 pip install requests
34
35 Ansible:
36 --------
37 sudo apt-get install software-properties-common
38 sudo apt-add-repository ppa:ansible/ansible
39 sudo apt-get update
40 sudo apt-get install ansible
41
42 SQL db:
43 -------
44
45 sudo apt-get install mysql-server
46
47 Set root passwd during installation (i.e. password_4_mysql_user_id)
48
49 sudo service mysql restart
50
51 Setup mysql:
52 ------------
53
54 mysql -u [username]-p
55 mysql -uroot -p
56
57 Create user (i.e. id=mysql_user_id psswd=password_4_mysql_user_id)
58   CREATE USER 'appc'@'%' IDENTIFIED BY 'password_4_mysql_user_id';
59   GRANT ALL PRIVILEGES ON *.* TO 'mysql_user_id'@'%';
60   SET PASSWORD FOR 'mysql_user_id'@'%'=PASSWORD('password_4_mysql_user_id');
61
62 Create schema
63   CREATE SCHEMA ansible;
64   show databases;
65   use ansible;
66   CREATE TABLE playbook (name VARCHAR(45) NOT NULL, value BLOB, type VARCHAR(60), version VARCHAR(60), PRIMARY KEY (name));
67   show tables;
68   CREATE TABLE inventory (hostname VARCHAR(45) NOT NULL, hostgroup VARCHAR(45), credentials VARCHAR(500), PRIMARY KEY (hostname));
69   SHOW COLUMNS FROM playbook;
70   SHOW COLUMNS FROM inventory;
71   GRANT ALL PRIVILEGES ON *.* TO 'mysql_user_id'@'%' IDENTIFIED BY 'password_4_mysql_user_id' WITH GRANT OPTION;
72   GRANT ALL PRIVILEGES ON *.* TO 'ansible'@'%' IDENTIFIED BY 'ansible_agent' WITH GRANT OPTION;
73   FLUSH PRIVILEGES;
74
75 Load db:
76 --------
77
78 python LoadAnsibleMySql.py
79
80 =============
81 CODE TESTING:
82 =============
83 1. Start RestServer: python RestServer.py
84
85 2. Try curl commands (case no secured REST: http & no authentication):
86
87 - Request to execute playbook:
88 curl -H "Content-type: application/json" -X POST -d '{"Id": "10", "PlaybookName": "ansible_sleep", "NodeList": ["host"], "Timeout": "60", "EnvParameters": {"Sleep": "10"}}' http://0.0.0.0:8000/Dispatch
89
90 response: {"ExpectedDuration": "60sec", "StatusMessage": "PENDING", "StatusCode": 100}
91
92 - Get results (blocked until test finished):
93 curl --cacert ~/SshKey/fusion_eric-vm_cert.pem --user "appc:abc123" -H "Content-type: application/json" -X GET  "http://0.0.0.0:8000/Dispatch/?Id=10&Type=GetResult"
94
95 response: {"Results": {"localhost": {"GroupName": "host", "StatusMessage": "SUCCESS", "StatusCode": 200}}, "PlaybookName": "ansible_sleep", "Version": "0.00", "Duration": "11.261794", "StatusMessage": "FINISHED", "StatusCode": 200}
96
97 - Delete playbook execution information
98 curl --cacert ~/SshKey/fusion_eric-vm_cert.pem --user "appc:abc123" -H "Content-type: application/json" -X DELETE  http://0.0.0.0:8000/Dispatch/?Id=10
99
100 response: {"StatusMessage": "PLAYBOOK EXECUTION RECORDS DELETED", "StatusCode": 200}