I'm running several LEMP VMs with mostly identical setups. Each of these VMs has a /etc/profile.d/00-aliases.sh containing a bunch of aliasses and functions to run on the server. Now, whenever I make a change to those aliasses/functions I have to manually copy/paste the file to the other servers.

I want to load the file from an external source every time I log in via SSH. I've seen this behaviour on other servers with a "Loading external scripts.." prompt on login. On top of that it would need some kind of local variables for the functions and some variables because there are slight variations in themes and foldernames on each server.

So best case scenario I'd have something like this for the variables (pseudocode):

var sitename = SiteA
var sitepath = /html/path/

and then one global bash.rc/aliasses file like this:

alias goroot = 'cd {sitepath}'
alias delses = 'rm -rf /var/session/'

Is this possible (with the variables), if yes, how? Where do I start to look?

  • 1
    Why don't you deploy the file with ansible or something similar? – Gerald Schneider Sep 24 '18 at 8:56
  • Sure that would work :) I'm using Gcloud Compute Engine; that makes sharing files between instances pretty easy. My main issue is how to get the variables working, because just having one static file shared between them only solves a part of the problem. Any ideas on that one? :) – Alex Timmer Sep 24 '18 at 8:59
  • 1
    ansible has host- and groupvars that can be automatically used during deployment. I'm not familiar with other systems, but I assume they have something similar. – Gerald Schneider Sep 24 '18 at 9:02

You can use ansible with the template module to deploy your files:




profile_d: /etc/profile.d/


sitename: SiteA
sitepath: /html/path/


alias goroot = 'cd {{ sitepath }}'
alias delses = 'rm -rf /var/session/'



- hosts lemp-hosts
  - name: copy aliases.sh
      src: templates/00-aliases.sh
      dest: "/{{ profile_d }}/00-aliases.sh"

Create an inventory, along with group- and hostvar files specific to your hosts on your control host. Then you can deploy the file with ansible-playbook playbooks/deploy_aliases.yml to all your hosts at once. Of course you can deploy all your configuration with a single playbook, ansible will only change files that have been changed. Manage your ansible directory with git and you even have revisions of your configuration in a single place.

  • Thanks for the detailed answer! I guess I'll forgo the known possibilities with gcloud and see if I can use ansible for this then :) – Alex Timmer Sep 24 '18 at 9:35

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.