-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use with_items ,when and tags in suitable #33
Comments
Suitable doesn't support these directives, since they basically exist to add logic to Ansible playbooks (as I understand it). However, with Suitable you have Python at your disposal, so these For example, from the docs, this statement: - name: "shut down Debian flavored systems"
command: /sbin/shutdown -t now
when: ansible_facts['os_family'] == "Debian" Would be written as follows with ansible: from suitable import Api
HOST = 'example.org'
api = Api(HOST)
# retrieve the facts
facts = api.setup().ansible_facts(HOST)
# conditional shutdown
if facts['ansible_os_family'] == 'Debian':
api.command('/sbin/shutdown -t now') |
Thank you for your feedback, Would you like to make Suitable support Ansible playbooks in the future? |
Probably not. If you have a good use case though, please see #21 and add a comment there. Maybe it makes sense to add support for it. |
I'm curious how this works for multiple hosts, for example right now I'm doing: def setup_cockroach():
for host in hostnames:
api = suitable.Api(host)
if not api.stat(path="/usr/local/bin/cockroach")['contacted'][host]['stat']['exists']:
api.shell('wget -qO- https://binaries.cockroachdb.com/cockroach-v19.1.5.linux-amd64.tgz | tar xvz')
api.shell('cp -i cockroach-v19.1.5.linux-amd64/cockroach /usr/local/bin')
setup_cockroach() But that loses the benefit of doing them all in parallel. With Ansible, you could set a register on the stat and check when: "{{register}}" to only run it on the hosts that you need to |
You can still do it in parallel, just that you need to do it a bit differently, to get maximum parallelisation. With your approach you will indeed run serially through all hosts. This is how I would approach it (note that this is completely untested code): def setup_cockroach():
# by default only 5 hosts are contacted in parallel ('serial' strategy),
# use the 'free' strategy to run it parallel on *all* hosts
api = suitable.Api(hostnames, strategy='free')
# this is run in parallel on all hosts
response = api.stat(path='/usr/local/bin/cockroach')
# next, gather the subset of hosts to use as installation targets
targets = []
for host in hostnames:
if not response.stat(host)['exists']:
targets.append(host)
# install in parallel on a subset of hosts
api = suitable.Api(targets, strategy='free')
api.shell('wget -qO- https://binaries.cockroachdb.com/cockroach-v19.1.5.linux-amd64.tgz | tar xvz')
api.shell('cp cockroach-v19.1.5.linux-amd64/cockroach /usr/local/bin') You probably don't want to use If you install mitogen, you might also get some additional speed boost. See |
That's awesome, thank you. Loving Suitable, with a Jupyter notebook it's pretty much exactly what I wanted for an interactive configuration management tool |
Thanks 😊 |
suitable is very good, but i don't know how to use it with when , with_items , and tags。
The text was updated successfully, but these errors were encountered: