chopsticks
chopsticks copied to clipboard
Adding some examples
Hi @lordmauve do you have some examples to share about how to use chopsticks?
Actually I am using Paramiko to create some remote dirs and execute a remote command but it's not clear if I can do the same with chopsticks.
You would use os.mkdir() to make directories and subprocess.check_call() and similar to execute the subprocess.
If you can write the function or functions you'd want to execute remotely, the docs should be fairly good on how to call it across remote hosts.
Thanks :)
I'm particularly interested to know if you have any general suggestions for structuring a chopsticks-based project to replace ansible roles / playbooks?
I don't think Chopsticks itself should be opinionated about project layout.
Purely as a suggestion however, there are two components that you might want to keep separate: code that you want to run remotely, and code that runs on your local orchestration host that drives it. How you divide these is up to you. You could, for example, write almost everything to run on the remote hosts and call it as one function on the orchestration host. The approach that most closely matches Ansible would be to have self-contained "tasks" that run remotely, controlled by "roles" that run on the orchestration host.
You could perhaps create Python packages like this:
-
your_site_name/roles/__init__.py
- package to contain code to run on orchestration host -
your_site_name/tasks/__init__.py
- package to contain functions to run on remote hosts
I hope that helps. Let me know how you get on :)