python - Running bash commands in Ansible task -
i porting makefile series of ansible tasks. make file has these 2 lines of code troubling me when comes ansible:
servers := shell mysql "select hostname servers" easy_install := wget https://bootstrap.pypa.io/ez_setup.py -o - | python firstly, what's appropriate ansible way use dynamic vars value of servers? value of servers depends upon environment, i.e. stage, production, etc.
secondly, don't want install python-setuptools package aptitude because have had nothing problems in past. how run wget shell command ansible?
it looks wanting download script , run command against number of servers.
the concept of 'hosts' in ansible playbook covers 'servers' concept - need populate inventory ansible can read hosts, or possibly pass in hosts variable when running playbook (lets call variable 'servers').
wget , running various commands standard ansible modules (get_url generalised name wget).
so, example playbook:
- hosts: "{{ servers }}" tasks: - name: file get_url: url: "https://bootstrap.pypa.io/ez_setup.py" dest: "/usr/ez_setup.py" - name: run command command: "python /usr/ez_setup.py" you call above playbook (lets call shipit.yaml) this:
ansible-playbook /usr/shipit.yaml --extra-vars "servers=10.0.0.1" you use add_hosts module , custom group name dynamically read servers database , populate custom group, run next set of commands against custom group hosts item.
you milage may vary depending on if need sudo enabled (sudo: yes) or not, , there may better way of running python script using command (command run every time no regard if has been run - not idempotent in other words).
hopefully above gives starting point.
Comments
Post a Comment