chopsticks icon indicating copy to clipboard operation
chopsticks copied to clipboard

Adding some examples

Open barrachri opened this issue 7 years ago • 4 comments

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.

barrachri avatar Apr 24 '17 11:04 barrachri

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.

lordmauve avatar Apr 24 '17 11:04 lordmauve

Thanks :)

barrachri avatar Apr 24 '17 11:04 barrachri

I'm particularly interested to know if you have any general suggestions for structuring a chopsticks-based project to replace ansible roles / playbooks?

meshy avatar May 20 '17 08:05 meshy

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 :)

lordmauve avatar May 22 '17 17:05 lordmauve