FastHandle - IT Operations Examples

FastHandle is fast operation tools for infrastructure configurations and tests.

User Tools

Site Tools


appendix:fabric-vs-others.html



Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
appendix:fabric-vs-others.html [2017/12/16 23:09]
kurihara
appendix:fabric-vs-others.html [2020/02/20 23:46] (current)
kurihara
Line 1: Line 1:
 [[:index.html#Appendix|Top#Appendix]] [[:index.html#Appendix|Top#Appendix]]
  
-======FastHandle(Fabricvs Other Tools======+======Python Fabric vs ssh vs Ansible======
  
-===== Fasthandle(Fabricvs Only ssh =====+\\ 
 +{{INLINETOC}} 
 +\\ 
 + 
 +===== Python Fabric vs Only ssh =====
  
     *FastHandle can easily deploy many servers.     *FastHandle can easily deploy many servers.
Line 10: Line 14:
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H x.x.x.x auth.pro -- hostname +$ fab -H x.x.x.x  -- hostname 
-$ fab -H x.x.x.x auth.stg -- hostname+
 vs vs
 +
 $ ssh x.x.x.x hostname $ ssh x.x.x.x hostname
 $ ssh -i ~/.ssh/id_rsa.pro x.x.x.x hostname $ ssh -i ~/.ssh/id_rsa.pro x.x.x.x hostname
Line 21: Line 26:
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab -H x.x.x.x auth.pro -- "echo "any host 192.168.100.1 gw 192.168.0.5" >> /etc/sysconfig/static-routes" +$ fab -H x.x.x.x  -- sudo "bash -c 'echo "any host 192.168.100.1 gw 192.168.0.5" >> /etc/sysconfig/static-routes'
-$ fab -H x.x.x.x auth.pro -- "echo 'any host 192.168.100.1 gw 192.168.0.5' >> /etc/sysconfig/static-routes"+
 vs vs
 +
 $ ssh -t x.x.x.x sudo "bash -c 'echo \"any host 192.168.100.1 gw 192.168.0.5\" >> /etc/sysconfig/static-routes'" $ ssh -t x.x.x.x sudo "bash -c 'echo \"any host 192.168.100.1 gw 192.168.0.5\" >> /etc/sysconfig/static-routes'"
 </sxh> </sxh>
  
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
-$ fab  -H x.x.x.x auth.pro -- "sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date '+%Y%m%d'`"+$ fab  -H x.x.x.x  -- sudo "bash -c 'sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date '+%Y%m%d'`'" 
 vs vs
 +
 $ ssh x.x.x.x  sudo "bash -c 'sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date '+%Y%m%d'`' " $ ssh x.x.x.x  sudo "bash -c 'sed s/192.168.100.10/192.168.50.10/g /etc/hosts > /etc/hosts.`date '+%Y%m%d'`' "
 </sxh> </sxh>
Line 35: Line 43:
 <sxh bash toolbar:false gutter:false> <sxh bash toolbar:false gutter:false>
 $ H="192.168.0.1,192.168.0.2" $ H="192.168.0.1,192.168.0.2"
-$ fab -H $H  auth.pro -- hostname+$ fab -H $H   -- hostname
  
 vs vs
Line 43: Line 51:
 </sxh> </sxh>
  
 +\\
 +===== Ansible Ad-Hoc Commands=====
 +http://docs.ansible.com/ansible/latest/intro_adhoc.html
 +
 +  *Ansible must be aware of the initial connection "yes/no".
 +
 +==== Ansible Options ====
 +
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -h
 +Usage: ansible <host-pattern> [options]
 +
 +Options:
 +  -a MODULE_ARGS, --args=MODULE_ARGS
 +                        module arguments
 +  --ask-vault-pass      ask for vault password
 +
 +  -i INVENTORY, --inventory-file=INVENTORY
 +                        specify inventory host path
 +                        (default=/etc/ansible/hosts) or comma separated host
 +                        list.
 +  -m MODULE_NAME, --module-name=MODULE_NAME
 +                        module name to execute (default=command)
 +
 +  Connection Options:
 +    -k, --ask-pass      ask for connection password
 +    --private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
 +    -u REMOTE_USER, --user=REMOTE_USER
 +                        connect as this user (default=None)
 +
 +  Privilege Escalation Options:
 +    -s, --sudo          run operations with sudo (nopasswd) (deprecated, use
 +                        become)
 +    -U SUDO_USER, --sudo-user=SUDO_USER
 +                        desired sudo user (default=root) (deprecated, use
 +                        become)
 +    -S, --su            run operations with su (deprecated, use become)
 +    --ask-sudo-pass     ask for sudo password (deprecated, use become)
 +    --ask-su-pass       ask for su password (deprecated, use become)
 +</sxh>
 +
 +
 +==== Example ====
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -i 192.168.0.10, all   -a "hostname"
 +$ ansible -i 192.168.0.10,192.168.0.11, all   -a "hostname"
 +
 +$ ansible -i 192.168.0.10,192.168.0.11, all   -a "sudo hostname"
 +$ ansible -i 192.168.0.10,192.168.0.11, all -s  -a "hostname"
 +</sxh>
 +
 +\\
 +>The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like “<”, “>”, “|”, “;” and “&” will not work (use the shell module if you need these features).
 +
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -i 192.168.0.30, all  -m shell -a  "hostname > /tmp/test.txt"
 +$ ansible -i 192.168.0.30, all  -m shell -a  "cat /etc/ssh/sshd_config |grep -i Root"
 +</sxh>
 +
 +\\
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -i 192.168.0.10, all   -u root -k -a "hostname"
 +SSH password:
 +192.168.0.10 | SUCCESS | rc=0 >>
 +root
 +</sxh>
 +
 +<sxh bash toolbar:false gutter:false>
 +$ vi hosts_test
 +[test-web]
 +192.168.0.10
 +192.168.0.11
 +
 +$ ansible test-web -i hosts_test -a 'hostname'
 +</sxh>
 +
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -i hosts_test  -u user01 -k -s -a "cat /etc/shadow"
 +</sxh>
 +
 +<sxh bash toolbar:false gutter:false>
 +$ ansible -s -K -B 1 -a "shutdown -h now" -i host1,host2 all
 +</sxh>
  
 \\ \\


appendix/fabric-vs-others.html.1513433371.txt.gz · Last modified: 2017/12/16 23:09 by kurihara