Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/bin/sh
  2. if [ -z "$1" ]; then
  3. echo "No hostname specified"
  4. echo "usage: ansible-ssh [hostname] [user=jsnow]";
  5. exit 1;
  6. fi
  7.  
  8. if [ -z "$2" ]; then
  9. USER="jsnow"
  10. else
  11. USER="$2"
  12. fi
  13.  
  14. IPV4S="inventory/ipv4.json"
  15.  
  16. if [ ! -f "$IPV4S" ]; then
  17. touch "$IPV4S" &&
  18. python2.7 inventory/openstack.py --list |
  19. jq -r "[._meta.hostvars | \
  20. to_entries[] | \
  21. {id: .key, \
  22. hostname: .value.openstack.name, \
  23. ipv4: .value.ansible_ssh_host}]" |
  24. tee $IPV4S
  25. fi
  26.  
  27. HOST=$(cat $IPV4S |
  28. jq -r --arg HOSTNAME "$1" '.[] | select(.hostname == $HOSTNAME) | .ipv4')
  29.  
  30. if [ -z "$HOST" ]; then
  31. echo "No such hostname '$1'"
  32. exit 2
  33. fi
  34.  
  35. ssh -o "UserKnownHostsFile /dev/null" \
  36. -o "LogLevel ERROR" \
  37. -t $USER@$HOST bash
Add Comment
Please, Sign In to add comment