Skip to content

Instantly share code, notes, and snippets.

@qrtt1
Last active February 18, 2016 01:18
Show Gist options
  • Save qrtt1/b05611f7bb827ffb6813 to your computer and use it in GitHub Desktop.
Save qrtt1/b05611f7bb827ffb6813 to your computer and use it in GitHub Desktop.
Ansible Dynamic Inventory
#!/bin/env sh
gcloud compute instances list --regexp .*foobarbar.* --format json \
| jq '{"web":{"vars": {"ansible_ssh_user":"i_am_the_king_of_the_world", "ansible_ssh_private_key_file":"/opt/ansible_pass.pem"}, "hosts": [.[].networkInterfaces[].accessConfigs[].natIP]}}'
exit 0
{
"web": {
"vars": {
"ansible_ssh_user": "i_am_the_king_of_the_world",
"ansible_ssh_private_key_file": "/opt/ansible_pass.pem"
},
"hosts": [
"130.231.253.55",
"104.100.153.66"
]
}
}
---
- hosts: web
sudo: yes
serial: 1
post_tasks:
- wait_for: port=3033
tasks:
- command: "update-you-software"
- command: forever restartall
# Run
# ansible-playbook -i nodelist.sh server_refresh.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment