Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a local command with fabric 2?

Tags:

I want to use Fabric and run a command on local, without having to establish any additional connections.

How do I do this in fabric 2? ... documentation seems to miss to give any example.

like image 448
sorin Avatar asked Aug 10 '18 20:08

sorin


People also ask

How do you answer prompts automatically with Python fabric?

The section about Prompts in the Fabric documentation says: The prompts dictionary allows users to control interactive prompts. If a key in the dictionary is found in a command's standard output stream, Fabric will automatically answer with the corresponding dictionary value.

What is fabric command?

Fabric is a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks. Fabric is very simple and powerful and can help to automate repetitive command-line tasks. This approach can save time by automating your entire workflow.


1 Answers

The design decision to drop the local command in Fabric 2 makes this more difficult, but I was able to simulate it by using Context from Invoke instead of Connection:

from fabric import Connection from invoke.context import Context  @task def hostname(c):     c.run('hostname')  @task def test(c):     conn = Connection('user@host')     hostname(conn)     local_ctx = Context(c.config)  # can be passed into @task;                                    # Connection is a subclass of Context     hostname(local_ctx) 
like image 181
phoibos Avatar answered Sep 18 '22 13:09

phoibos