title: how to edit hostname file using fabric
body: <p>I have change my hosts file,so how to change hostname.my system is ubuntu.
  eg my hosts file:</p>
  
  <pre><code>192.168.0.100 host1.mydomain.com
  192.168.0.101 host2.mydomain.com
  </code></pre>
  
  <p>I wanna the hostname file under /etc/hostname of host1 to host1.mydomain.com,the hostname file of host2 to host2.mydomain.com</p>
  
  <p>how to do that using fabric?
  I have to ssh every host and edit the hostname file,does fabric can do this?</p>
  
  <p>I didn't mean to use <code>hostname</code> command but to edit the /etc/hostname file.
  I mean how to use fabric to do that:
  such as:</p>
  
  <pre><code>def update_hostname():
    get("/etc/hosts","hosts")
    hosts_content = file("hosts")
    **hostname = ·get the hostname corespond to ip·**
    get("/etc/hostname","hostname")
    update `hostname file`
    put("hostname","/etc/hostname")
  </code></pre>
  
  <p>how get the ip? because fabric do the job on every host, and the hostname is correspond to each host. I need to know the which host the job is working and then get the ip back,then get the hostname correspond the the ip,and final update the hostname file.
  <img src="https://i.stack.imgur.com/AnUuV.png" alt="enter image description here"></p>