I'm trying to run a fabric script to change the IP of a server:
from cStringIO import StringIO
import os
import fabric
import fabric.api
import jinja2
fabric.state.env['hosts'] = '10.1.0.4'
def render(tpl_path, context):
path, filename = os.path.split(tpl_path)
template_stream = jinja2.Environment(loader=jinja2.FileSystemLoader(path or './')).get_template(filename).stream(context)
output_stream = StringIO()
for chunk in template_stream:
output_stream.write(chunk)
return output_stream
def change_ip():
ifcfg_ens192 = render("ifcfg.j2", {
"device": "ens192",
"ip_address": "10.1.0.20",
"prefix": "24"
})
fabric.operations.put(ifcfg_ens192, "/etc/sysconfig/network-scripts/ifcfg-ens192", use_sudo=True, mirror_local_mode=True)
fabric.operations.sudo("service network restart")
fabric.tasks.execute(change_ip)
But whenever the IP address changes, fabric freezes with following output:
[10.1.0.4] Executing task 'change_ip'
[10.1.0.4] Login password for 'root':
[10.1.0.4] put: <file obj> -> /etc/sysconfig/network-scripts/ifcfg-ens192
[10.1.0.4] sudo: service network restart
[10.1.0.4] out: Restarting network (via systemctl):
I'd like to run other tasks after I change IP tasks. Is there anything I can do to run this?