-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshfs.py
85 lines (76 loc) · 2.52 KB
/
sshfs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python2
import commands
import cgi
print "content-type: text/html"
print
#input from HTML pages
DriveSize=cgi.FormContent()['size'][0]
Cip=cgi.FormContent()['cip'][0]
Sip=cgi.FormContent()['sip'][0]
Spass=cgi.FormContent()['spass'][0]
Cpassword=cgi.FormContent()['cpass'][0]
Vg=cgi.FormContent()['vg'][0]
UserName=cgi.FormContent()['user'][0]
#creating user at server side
UserStatus=commands.getstatusoutput("sshpass -p {2} ssh -o stricthostkeychecking=no -l root {0} sudo useradd {1}".format(Sip,UserName,Spass))
if UserStatus[0] == 0:
print "New User Successfully Created"
PasswordStatus = commands.getstatusoutput("echo '{1}' | sshpass -p {2} ssh -o stricthostkeychecking=no -l root {3} sudo passwd {0} --stdin".format(UserName,Cpassword,Spass,Sip))
print PasswordStatus
if PasswordStatus[0]==0:
print "Pasword Set Successfully.Your Account is ready to use."
#making entry for client and server to be configured using Ansible
y="""[web]
{0} ansible_ssh_user=root ansible_ssh_pass={1}
[client]
{2} ansible_ssh_user=root ansible_ssh_pass={3}
""".format(Sip,Spass,Cip,Cpassword)
commands.getstatusoutput("sudo mkdir /webcontent/ansible/hosts")
commands.getstatusoutput("sudo chown apache /webcontent/ansible/hosts")
f3=open('/webcontent/ansible/hosts','w')
f3.write(y)
f3.close()
x="""---
- hosts: web
tasks:
- package:
name: "sshpass-1.06-1.el7.x86_64"
state: present
- lvol:
vg: "{0}"
lv: "{1}"
size: "{2}"
- file:
state: directory
path: "/sshcloud/{1}"
owner: {1}
mode: 0700
- filesystem:
fstype: ext4
dev: "/dev/{0}/{1}"
- mount:
path: "/sshcloud/{1}"
src: "/dev/{0}/{1}"
fstype: ext4
state: mounted
- service:
name: "sshd"
state: restarted
- hosts: client
tasks:
- package:
name: "fuse-sshfs-2.5-1.el7.x86_64"
state: present
- file:
state: directory
path: "/media/{1}"
- package:
name: "sshpass-1.06-1.el7.x86_64"
state: present
""".format(Vg,UserName,DriveSize)
f1=open("/webcontent/scripts/ansshfs.yml",'w')
f1.write(x)
f1.close()
print commands.getstatusoutput("sudo ansible-playbook ansshfs.yml -i /webcontent/ansible/hosts")
commands.getstatusoutput("sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sshpass -p {4} sshfs root@{3}:/sshcloud/{2} /media/{2}".format(Cpassword,Cip,UserName,Sip,Spass))
print "Successfully created"