Search code examples
pythonfabric

Launch Fab File inside a python script


I have a fab script, it works fine. To start it, I execute:

fab -H 192.168.xx.xx deployFiles deployConfiguration:'master',7

deployFiles and deployConfiguration are both functions in my fabfile.py. 'master' and 7 are my parameters for deployConfiguration

I have another Python script and I want to launch, the previous fab command inside him.

How can I execute, my fabfile with these parameters from a Python script?


Solution

  • You just import them, and call them. Using either the settings context manager or setting the relevant settings on fabric.api.env

    from fabric.context_managers import settings
    from fabfile import deployFiles, deployConfiguration
    
    with settings(host_string='[email protected]'):
        deployFiles()
        deployConfiguration('master', 7)