[Charlotte-pm] Is there an Ansible solution to this deployment process?

Yanick Champoux yanick at babyl.ca
Fri Aug 27 07:06:54 PDT 2021


Hi William!

On Thu, 26 Aug 2021, at 10:22 PM, William McKee wrote:
> 1. I only have 1 server that I need to deploy sites onto. Don't expect this to change. Can I simplify the server setting along the following lines:
> 
> ```
> all:
>   hosts:
>     'knowmad.com':
>       ansible_ssh_host: 192.168.0.1
>       ansible_ssh_user: dancer
> ```

Oooh. I see. You are adding configs to your own server each time you add a new customer, rather than going and installing something on their server. I misunderstood that the first time around. :-) And yes, absolutely, you can totally have an inventory of a single host. 

> 
> 1a. What file do I put this information into? Does it belong in `./playbooks/onboard.yml`?

It's in `inventory.yml` or `inventory.ini`, dependending on the format you're using.



> 
> 1b. Since I'm not onboarding a server but rather using ansible to deploy a new site within a multi-tenant web app, I may rename that file to `./playbooks/deploy.yml`. Does that make sense? Or does this sound confusing?


I'd say that "deploy" is maybe a tad generic. But hey, if it works for you, it works for you. Mostly if for the time being you have only one playbook. :-)  

And that goes for the roles as well. In my example I went Full-Metal Best Practices and created a role, with task files for the different subtasks. You could totally throw everything in a single playbook, considering how little there is to it. 



> 
> 2. For the site specific configurations, I already have a perl script that uses Template based config files to build the domain specific configuration files needed for a new site. Perhaps I could replace that with Ansible + jinja2 at a future date. I'd need to figure out how to pass in the domain specific info when deploying a new site.

As a first pass you can use your perl script to create the config files and populate the `roles/*/files` directory. But if you have time, throw a quick glance at Jinja2. Honestly it's extremely close to Mustache / TT / Mason, so changing from one to the other is pretty painless (well, that's depending of how tortuous your templates are, I guess).


> 
> 3. It appears that I'll need to build a new set of ansible tasks for each domain. Yes? Or, is there a way to define placeholders that can be passed into a task via the ansible command line?

Yup. You can override/define variables from the command line, and you can pass variables to roles.


- name; do the thing, for sitename 
  include_tasks: ./do_the_thing.yml
  vars:
    sitename: '{{ weird_env_variable }}'



And on the command line

$ ansible-playbook -e weird_env_variable=potato .... 

(of course you could also have done `ansible-playbook -e sitename=potato ....` directly and skip the var mapping
in the task)

> 
> 4. Do I run the ansible client on my workstation and let it connect to the server? Do I need to install any ansible components on the server or only on my workstation? or both?

You run Ansible from your workstation. All that the remote hosts need is ssh enabled and Python.


> 
> 5. In addition to the site-specific files, I also need to push up any edits to the Perl libs, etc. I'm currently using rsync to do so. Wondering if I may be better off using ansible to manage the entire deployment process to the server.

In addition of calling the shell commands yourself, there are a few Perl-centric modules for Ansible. Like https://docs.ansible.com/ansible/latest/collections/community/general/cpanm_module.html (that one is core) and https://github.com/swfz/ansible-plenv (that one is part of the community set of roles)


Joy,
`/anick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/charlotte-pm/attachments/20210827/17012c95/attachment-0001.html>


More information about the Charlotte-pm mailing list