Kim Rudolph

Ansible Snippets

Task: Cache Warmup for Authenticated Users

- name: Login
  uri:
    url: http://{{ application }}/signin
    method: POST
    body: "username={{ exampleuser }}&password={{ examplepassword }}&enter=Login"
    status_code: 302
    HEADER_Content-Type: "application/x-www-form-urlencoded"
  register: login
- name: Cache warmup 
  uri:
    url: http://{{ application }}/{{ item[0] }}/{{ item[1] }}
    method: GET
    return_content: no
    HEADER_Cookie: "{{login.set_cookie}}"
  with_nested:
    - [ 'optional', 'categories', 'like', 'usernames' ]
    - [ 'account',
        'account/information',
        'projects'
      ]

Task: Update docker container unstarted

- name: Update my container
  docker:
    name: mycontainer
    image: my-private-hub/mycontainer:latest
    hostname: mycontainer
    state: present
    pull: always

Task: Update docker container started

- name: Update and start my container
  docker:
    name: mycontainer
    image: my-private-hub/mycontainer:latest
    hostname: mycontainer
    state: reloaded
    pull: always
    ports:
    - "80:8080"
    env:
      TYPE: "my-env-value"
    volumes:
    - '/path/to/mounted/configuration:/root/configuration:rw'

Task: Copy templated bin files and make them executable

- name: copy templated bin files
  template: src={{ item }} dest={{ bin_directory }}/{{ item | basename | regex_replace('\.j2','') }} mode="a+x"
  with_fileglob:
    - templates/bin/*.j2