Ansible-Pull is a great way to configure your servers at build time. I use the Red Hat Kickstart method of building a server, so configuration using ansible is just one line in the post installation portion of the kickstart file:
ansible-pull -d /tmp/ansprod_repo -U git://ansible.nyc.mizuhocap.com/ansprod-pull
These are the steps necessary for using ansible-pull:
* The first thing is to create a git repository
1) copy your files into a directory:
??? autofs
? ??? files
? ? ??? auto.files.RHEL6
? ? ??? auto.home.RHEL6
? ? ??? auto.install.RHEL6
? ? ??? auto.master.RHEL6
? ? ??? auto.master.RHEL7
? ? ??? default_server.autofs.RHEL7
? ? ??? home.autofs.RHEL7
? ??? tasks
? ??? main.yml
??? certs
? ??? files
? ? ??? MCM-ca.pem
? ??? tasks
? ??? inv
? ??? main.yml
??? cfgrun
? ??? files
? ? ??? cfgrun.sh
? ??? tasks
? ??? main.yml
??? etcfiles
? ??? files
? ? ??? krb5.conf
? ? ??? ldap.conf
? ? ??? profile
? ? ??? snmpd.conf
? ??? tasks
? ??? main.yml
??? file
??? issue
? ??? files
? ? ??? issue
? ??? tasks
? ??? main.yml
??? local.yml
??? nsswitch
? ??? files
? ? ??? nsswitch.conf
? ??? tasks
? ??? main.yml
??? ntpd
? ??? files
? ? ??? ntp.conf
? ??? tasks
? ??? main.yml
...
You’ll notice local.yml. This will automatically be executed by ansible after the git repository is downloaded. My local-yml looks like this:
[ansprod@emperor /files/ir/git/ansprod-pull]$ cat local.yml;
- hosts: localhost
user: root
tasks:
- include: sudo/tasks/main.yml
- include: screen/tasks/main.yml
- include: postfix/tasks/main.yml
- include: ssh/tasks/main.yml
- include: sssd/tasks/main.yml
- include: issue/tasks/main.yml
- include: ntpd/tasks/main.yml
- include: nsswitch/tasks/main.yml
- include: etcfiles/tasks/main.yml
- include: autofs/tasks/main.yml
- include: selinux/tasks/main.yml
- include: certs/tasks/main.yml
each of my tasks in main reference another yml file for one of the configurations I want to implement. Each of these yml files that get called contain further tasks:
---
-
copy: "src=/tmp/ansprod_repo/sudo/files/sudoers dest=/etc/sudoers owner=root group=root mode=0600 backup=yes"
name: "install /etc/sudoers"
-
copy: "src=/tmp/ansprod_repo/sudo/files/admins dest=/etc/sudoers.d/admins owner=root group=root mode=0600 backup=yes"
name: "install /etc/sudoers.d/admins"
-
copy: "src=/tmp/ansprod_repo/sudo/files/dev dest=/etc/sudoers.d/dev owner=root group=root mode=0600 backup=yes"
name: "install /etc/sudoers.d/dev"
-
copy: "src=/tmp/ansprod_repo/sudo/files/application dest=/etc/sudoers.d/application owner=root group=root mode=0600 backup=yes"
name: "install /etc/sudoers.d/application"
-
copy: "src=/tmp/ansprod_repo/sudo/files/usercmds dest=/etc/sudoers.d/usercmds owner=root group=root mode=0600 backup=yes"
name: "install /etc/sudoers.d/usercmds"
* you’ll notice that my ansible-pull statement above downloads the git repository into : /tmp/ansprod_repo .
note also, that the src files in my main.yml above also use /tmp/ansprod_repo as the location that those files will be located in.
* now that you have all your directories and playbooks in order, create the git repository:
mkdir ansprod_repo
cd ansprod_repo
git init --shared `pwd`
git add .
git commit -m "First commit"
git remote add origin git://servername/ansprod_repo
git remote -v # Verifies the new remote URL
git push origin master
Further reading for git: http://rogerdudler.github.io/git-guide/
now just run for a test:
ansible-pull -d /tmp/ansprod_repo -U git://ansible.nyc.mizuhocap.com/ansprod-pull