-1

I've got a git repo, I've got my playbooks and hosts. Now what?

What is the recommended way to get my /etc/ansible folder on my GitLab? I can just create the repo, but then how and when do I pull this? What about the .git folders?

I tried keeping a copy on /home/user/git/ansible and symlink that to /etc/ansible but ansible can't follow that.

How should this be done?

(I'm also interested in some good reads about how to work properly with git)

Frank Vermeulen
  • 157
  • 2
  • 8

1 Answers1

4

Personally I store nothing in /etc/ansible. But I install and run ansible using a virtualenv so /etc/ansible was never there for me.

You definitely should look at the official recommended layout, but my minimal ansible hierachy is as follow:

inventories
    hosts
    vars
roles
    role1
    role2
    ....
ansible.cfg
site.yml

I clone the repository to /home/victor/git/ansible and I put these lines in my bashrc to set the default ansible paths:

export ANSIBLE_INVENTORY=/home/victor/git/ansible/inventories/hosts
export ANSIBLE_CONFIG=/home/victor/git/ansible/ansible.cfg

There are two rules that I always follow:

  1. Everytime before I run a playbook, I pull from git to make sure I am running the latest version.
  2. Whenever I make a change to the playbook, I would always run them first to make sure there are no error before I commit to the repository.

If you are using ansible to distribute secrets or credentials, you also want to use ansible-vault to encrypt them before you commit to git. DO NOT put any plain credentials on a git repository.

I suppose in this use case having a .git folder is not an issue at all (I guess you didn't want a .git folder somewhere in /etc/).

Victor Wong
  • 478
  • 4
  • 9