python-fabric-manually set host parameter
Question: I want to insert my env.host manually.I have file having list of diff
env.host.something like this:

My host.py:

    
    
     @task
     def v2bg():
     env.hosts = ["12.12.11.132","13.10.18.22"]
    
     @task
     def api():
     env.hosts = ["4.3.81.27:2201", "4.3.1.7:2202", "20.3.18.07:2203", "60.83.581.27:2204"]
    
     @task
     def emailapi():
    env.hosts = ["30.40.50.56:2201", "40.40.36.56:2202"]
    
     @task
     def v2emailapi():
     env.hosts = ["20.18.148.30:2201", "20.18.48.3:2202"]
    

My emailapi.py

    
    
    import host
    from fabric.api import *
    from fabric.context_managers import *
    from fabric.contrib import *
    
    env.user = "ubuntu"
    env.key_filename = "~/Documents/Pem/sec"
    env.parallel = True
    env.warn_only = True
    

I want my emailapi.py manually pick up these Ip by importing host.py file. How
can i do that i am still in confuse??Please help me out.

    
    
      "networks": {
        "v4": [
         {
           "ip_address": "104.131.186.241",
           "netmask": "255.255.240.0",
           "gateway": "104.131.176.1",
           "type": "public"
         }
       ],   
    

I more thing, if i want to retrieve my ip_address and set automatically
env.host how can i acheive it.


Answer: I think you want to do this. Let me know if it works.

my_roles.json

`{ "ip": [ "user@someip.example.com", "user@someip.example.com" ], "ip1": [
"user@someip.example.com", "user@someip.example.com" ] } ` fabfile.py

    
    
    from fabric.api import env, run, task
    import json
    
    def load_roles():
        with open('my_roles.json') as f:
            env.roledefs = json.load(f)
    
    load_roles()
    
    @task
    def my_task():
        run("hostname")
    

CLI

`fab -R ip my_task`

output from running "my_task" for each of web1 and web2 is here

