---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Memcached cache flush
  hosts: memcached_all
  gather_facts: false
  user: root
  tasks:
    - name: Flush all of the cache in memcached
      shell: |
        echo 'flush_all' | nc $(awk '/^\-l/ {print $2}' /etc/memcached.conf | awk -F, '{ print $1 }') $(awk '/^\-p/ {print $2}' /etc/memcached.conf)

---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Memcached cache flush
  hosts: memcached_all
  gather_facts: true
  user: root
  vars:
    memcached_conf_dest:
      debian: "/etc/memcached.conf"
      redhat: "/etc/sysconfig/memcached"
  tasks:
    - name: Ensuring nc is installed
      package:
        name: nc
        state: present
    - name: Flush all of the cache in memcached
      shell: |
        echo 'flush_all' | nc $(awk '/^\-l/ {print $2}' {{ memcached_conf_dest.get(ansible_os_family | lower) }} | awk -F, '{ print $1 }') $(awk '/^\-p/ {print $2}' {{ memcached_conf_dest.get(ansible_family | lower) }} )

Add nc to the packages to install during upgrade
Add nc to the packages to install during upgrade

Upgrade uses nc, but doesn't enforce its presence.
This makes sure nc is installed.

On top of it, the filenames used are ubuntu ones,
so this moves to use a var to find which filename
should be used for centos.

See also the issue here:
http://logs.openstack.org/periodic/periodic-openstack-ansible-
upgrade-ceph-master-centos-7/d2fc540/
console.html#_2017-05-30_08_23_40_475244

Change-Id: I3ee2dfd6e435fb4d92a57e2debf7f001f7c03f98
