32

OVERVIEW

I'd like to have reliable django deployments and I think I'm not following the best practices here. Till now I've been using fabric as a configuration management tool in order to deploy my django sites but I'm not sure that's the best way to go.

In the high performance django book there is a warning which says:

Fabric is not a configuration management tool. Trying to use it as one will ultimately cause you heartache and pain. Fabric is an excellent choice for executing scripts in one or more remote systems, but that's only a small piece of the puzzle. Don't reinvent the wheel by building your own configuration management system on top of fabric

So, I've decided I want to learn ansible.

QUESTIONS

  • Does it make sense using both fabric and ansible tools somehow?
  • Is it possible to use ansible from my windows development environment to deploy to production centos(6/7) servers?
  • There is this nice site https://galaxy.ansible.com/ which contains a lot of playbooks, any good recommendation to deploy django on centos servers?
BPL
  • 9,632
  • 9
  • 59
  • 117
  • 1
    Fabric and Ansible both enable orchestration in a similar fashion, so using both does not make sense as Fabric would be a subset of Ansible. The answer to the second question is yes. I do not know the third, so I leave this as a comment. – Matthew Schuchard Sep 07 '16 at 12:57
  • 1
    For question 2, [it's not possible to use a Windows server as the control machine](http://docs.ansible.com/ansible/intro_windows.html#reminder-you-must-have-a-linux-control-machine). You could run a virtual machine locally, and use ansible from there. – Alasdair Sep 07 '16 at 13:02
  • @Alasdair I guess Matt Schuchard meant having ansible running on cygwin. Let's assume I'd use a virtual machine locally to deploy my stuff, what would be the main inconvenients of that approach (I'll develop my django sites on windows)? Fabric is fully multiplatform and that's great... If ansible is not the best choice for my use-case, any other good config management tool recommendation (windows on dev box & centos on production boxes)? – BPL Sep 07 '16 at 13:59
  • The link I included specifically says Cygwin is not supported. Using a virtual machine to run ansible complicates your setup, only you can tell whether the benefits of ansible are worth that complexity. I'm afraid I can't help with config management tool recommendations. – Alasdair Sep 07 '16 at 14:27
  • 1
    Actually I think I was assuming using 'LINE' on Windows 10 (or maybe not). Otherwise, @Alasdair is probably correct on point 2. – Matthew Schuchard Sep 07 '16 at 14:44
  • So I still see this on the Ansible questions, and it seems we have collectively answered 1 and 2, and 3 is going to be opinion/trial and error. Would you like to try out the playbooks on galaxy and then self-answer based on the information provided thus far? – Matthew Schuchard Sep 08 '16 at 12:51
  • @MattSchuchard First of all, thanks for your answer. I'm really struggling with this topic for few days already (I'm trying to find out a suitable workflow when using windows as a control machine). I've opened another 2 related questions, [this](http://stackoverflow.com/questions/39378247/absolute-path-error-when-building-wheel) and [this](http://stackoverflow.com/questions/39388050/good-deployment-workflow-using-windows-as-a-machine-control). Today or tomorrow I'll try to find a slice of time to give it a shot running ansible from vagrant and I'll post more details about – BPL Sep 08 '16 at 13:06
  • @MattSchuchard If that possibility doesn't feel alright I guess I'll continue using fabric alone, even if that's not the best solution :( – BPL Sep 08 '16 at 13:07
  • I am so sorry that you are stuck using Windows. That would be a reason for most people to not work at a company. Does your company policy forbid LINE on Windows 10 or are you on an earlier version? – Matthew Schuchard Sep 08 '16 at 13:09
  • 1
    @MattSchuchard To be honest, I'm really happy coding stuff on windows, I'm really productive on that platform and I code my stuff really fast. But of course, deploying such stuff on windows would be a pain. I'm using windows7 but if you tell me upgrading to windows10 will bring me a lot of advantages I could consider it of course – BPL Sep 08 '16 at 13:15
  • @MattSchuchard [Related to this topic](http://stackoverflow.com/questions/39392695/nvidia-drivers-on-windows-subsystem-linux) – BPL Sep 08 '16 at 13:48
  • They're not really the same tool. Ansible is a configuration management lib which includes tools to support for fact gathering, idempotence, package installs, services daemons. Fabric runs commands and shells remotely - you would then have to write your own package installers, idempotency checks, etc... They can be complementary but Ansible is more specialized than Fabric. – JL Peyret Aug 14 '18 at 17:08

1 Answers1

20

Does it make sense using both fabric and ansible tools somehow?

Yes. All your logic should live in Ansible and you can use Fabric as a lightweight wrapper around it.

fab deploy

is easier to remember than, e.g.

ansible-playbook -v --inventory=production --tags=app site.yml

Is it possible to use ansible from my windows development environment to deploy to production centos(6/7) servers?

Sounds like you can't. Alternatively, If you use Fabric, it could copy your ansible playbooks up to a server (or pull directly from git) and run ansible from there.

Pete
  • 2,503
  • 4
  • 21
  • 20
  • Thanks for the answer +1. Before validating your nice answer, do you know where can i find how to run ansible playbooks directly on the servers? I thought this was only possible from a linux control machine. It sounds like a reasonable good workflow if it's so, fabric+ansible, nice combo! :) – BPL Sep 09 '16 at 21:20
  • Just make one of your Linux servers the "control machine". It can both run Ansible and be configured by Ansible at the same time. Fabric wrap-up SSHing to that machine (from your Windows box) and running the playbooks. – Pete Sep 12 '16 at 17:01
  • Thanks a lot! I'll give it a shot this week to that approach ;-) – BPL Sep 12 '16 at 17:06
  • 11
    I don't see the point in the fabric part. How is that any better than a bash alias for the ansible command? – wobbily_col Feb 24 '17 at 10:33
  • 1
    @wobbily_col more portable, easier to share, easier to write more complex scripts, etc. Those may not be important in all situations though. – Pete Feb 26 '17 at 17:52
  • @Pete, you dont have to remember the command. Just use `zsh` or `ipython`, and use history search in `vi`/`emacs` mode. Its very easiy once you get a little bit used to a different process of storing command scripts. – alpha_989 Mar 19 '18 at 16:48
  • I like to use Ansible for setting the remote host in a specified (and version controlled) idempotent state. I then use Fabric to do one-time maintenance tasks (like uninstalling a package) that aren't well suited to perform from Ansible (e.g. having to keep around a uninstalled packages list forever in some file). I think they make a great combination of tools – Adam Lindberg Apr 12 '21 at 11:44