I would like to have a CI job run an ansible playbook, but struggle with the most scalable and manageable way. I have a playbook that runs everywhere, the difference is the inventory file. I want the inventory file to sit in a repo and be able to call it through CI. How do I accomplish this, and is it even the best way?
Hello @brentjweaver! I’ve been looking for some community content about this topic. Have you seen the following posts? Let me know if that helps you.
I figured out what I needed. I can pull the inventory Gil from local repo using $CI_PROJECT_URL and whet.
A more comprehensive example is:
variables: files_needed: "inventory playbook.yml requirements.yml users.yml " stages: - prep - install - cleanup prep_job: stage: prep script: - export TMPDIR=$(mktemp -d) - mkdir $TMPDIR/roles - for I in $files_needed; do wget -O $TMPDIR/$I $CI_PROJECT_URL/raw/master/$I; done - ansible-galaxy install -r $TMPDIR/requirements.yml -p $TMPDIR/roles - cd $TMPDIR - ansible-playbook -i inventory -e @users.yml -u root playbook.yml - cd / - rm -rfv $TMPDIR
What I was seeking is a way to pull the inventory (and any other files) into my pipeline and I was able to do it with wget and a bash one-liner. What I seek is that easy button for my users, so when they create a project it’s pretty uniform to get CI to work. Now I need to figure out how to templatize the .gitlab-ci.yml file. With a consistent convention and a templated CI file, what could go wrong?!?!?