Ansible new project

2020, Nov 28    

This is my checklist of what to include when starting a new project.

This is a rought outline, and it should be put in a .tar.gz for quick startup.

  1. Create the inventory file

    e.g. echo newserver >> inventory

  2. Create the ansible.cfg file.

    Content is something like this

     [defaults]
     inventory = inventory
     roles_path = ./roles-ext:./roles
     pipelining = True
    
  3. Create a role_req.yml for dependencies

    Content is comething like

     #- src: git+https://gitlab.com/<somerepo>
     #  name: server-someserver
    

    See galaxy docs for syntax

    I intentionaly do not call it requirements.yml to avoid any python confusion.

  4. Create the roles directory for external roles mkdir roles_ext

  5. Fetch roles using ansible-galaxy install -r role_req.yml -p roles-ext (if you added any)

  6. Add an initial generic playbook.yml

    Content is comething like

    - hosts: all
      become: true
    
      task:
      - name: say hi
        debug: msg="hi"
    
  7. Spin up server, reset passwords and such

  8. Add group vars and host_vars passwords file

    I follow [my own suggestion]/ansible-user/.

  9. Ensure you have ssh access to the server ssh user@newserver

  10. Run the playbook ansible-playbook playbook.yml

    check that it works

  11. Add the gitlab-ci part

    See [the post about that]/Ansible/.

  12. Do git init

  13. create .gitignore with the following entries

    vault-password
    roles_ext
    
  14. Create a vault password file and put it in vault-password

  15. Encrypt the password files ansible-vault encrypt --vault-password-file vault-password host_vars/*/passwords.yml

  16. Add the lot to git git add . and git commit -m "first commit"