forked from abenokraitis/cldemo-automation-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-puppet-agents.py
More file actions
executable file
·61 lines (52 loc) · 2.36 KB
/
install-puppet-agents.py
File metadata and controls
executable file
·61 lines (52 loc) · 2.36 KB
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
#! /usr/bin/env python
# This script installs the puppet agent on the hosts specified in the command
# line arguments. This script assumes that the 'cumulus' user has passwordless
# sudo enabled on the target devices.
import sys
import paramiko
import time
import os
from paramiko import SSHClient
from multiprocessing import Process
def go(host):
expect = paramiko.SSHClient()
expect.set_missing_host_key_policy(paramiko.AutoAddPolicy())
expect.connect(host, username="cumulus", password="CumulusLinux!")
if "server" in host:
commands = ['sudo wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb',
'sudo dpkg -i puppetlabs-release-pc1-xenial.deb',
'sudo apt-get update',
'sudo apt-get install puppet-agent -qy',
"sudo echo 'server = oob-mgmt-server.lab.local' | sudo tee /etc/puppetlabs/puppet/puppet.conf -a",
'sudo /opt/puppetlabs/bin/puppet agent --test']
elif "leaf" in host or "spine" in host:
commands = ['sudo wget https://apt.puppetlabs.com/puppetlabs-release-pc1-jessie.deb',
'sudo dpkg -i puppetlabs-release-pc1-jessie.deb',
'sudo apt-get update',
'sudo apt-get install puppet-agent -qy',
"sudo echo 'server = oob-mgmt-server.lab.local' | sudo tee /etc/puppetlabs/puppet/puppet.conf -a",
'sudo /opt/puppetlabs/bin/puppet agent --test']
for line in commands:
stdin, stdout, stderr = expect.exec_command(line, get_pty=True)
stdout.channel.recv_exit_status()
print("%s: %s"%(host, line))
os.system('sudo /opt/puppetlabs/bin/puppet cert sign %s.lab.local'%host)
for line in ['sudo /opt/puppetlabs/bin/puppet agent --test',
'sudo service puppet start']:
stdin, stdout, stderr = expect.exec_command(line, get_pty=True)
stdout.channel.recv_exit_status()
print("%s: %s"%(host, line))
expect.close()
if __name__ == "__main__":
try:
hostnames = sys.argv[1].split(',')
except:
print("Usage: install-puppet-agents.py [leaf01,leaf02,etc]")
sys.exit(-1)
processes = []
for host in hostnames:
p = Process(target=go, args=(host,))
p.start()
processes.append(p)
for p in processes:
p.join()