---

- name: Install packages
  yum:
    name:
      - memcached
      - libmemcached

- name: Deploy configuration
  template: src=memcached.j2 dest=/etc/sysconfig/memcached
  notify: restart memcached

- name: Handle memcached ports
  iptables_raw:
    name: memcached_ports
    state: "{{ (memcached_src_ip | length > 0) | ternary('present','absent') }}"
    rules: |
      -A INPUT -m state --state NEW -p tcp --dport {{ memcached_port }} -s {{ memcached_src_ip | join(',') }} -j ACCEPT
      -A INPUT -p udp --dport {{ memcached_port }} -s {{ memcached_src_ip | join(',') }} -j ACCEPT
  when: iptables_manage | default(True)

- name: Start and enabled the service
  service: name=memcached state=started enabled=yes
