Skip to content

Instantly share code, notes, and snippets.

@mancdaz
Last active August 29, 2015 14:22
Show Gist options
  • Save mancdaz/aa6593b7b18a96b48066 to your computer and use it in GitHub Desktop.
Save mancdaz/aa6593b7b18a96b48066 to your computer and use it in GitHub Desktop.

#Removing a container entirely

NB - these instructions are based on a juno install, so files and locations contain references to rpc_*

Let's say I have 3 keystone containers, and I want to remove one of them. There are essentially 3 steps

  1. Remove it from the user config file: /etc/rpc_deploy/rpc_user_config.yml
  2. Remove the container from the inventory - if you didn't do this, the container would get recreated the next time you ran the 'setup' part of the ansible playbooks, because the inventory still has references to it
  3. Destroy the container - this physically removes the container from the host that is running it

For all steps, we will assume that ${BASE} is wherever you have the os-ansible-deployment directory

####Step 1 remove from config

Find where you have your keystone hosts defined in /etc/rpc_deploy/rpc_user_config.yml

infra_hosts:
  aio1:
    ip: 172.29.236.100
    affinity:
      keystone_container: 3

Edit to remove one of the containers

infra_hosts:
  aio1:
    ip: 172.29.236.100
    affinity:
      keystone_container: 2

####Step 2 remove from inventory

There is a python tool in the scripts directory that can be used to manage the contents of the inventory. We will use this to remove references to one of our keystone containers.

First, use it to see that we have 3 keystone containers currently listed in the inventory (-f is used to tell the script what inventory file you want to manage, -l lists the contents of the inventory)

# cd ${BASE}
# scripts/inventory-manage.py -f /etc/rpc_deploy/rpc_inventory.json -l|egrep 'container_name|^\+|keystone'
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+
| container_name                              | is_metal | component           | physical_host | tunnel_address | ansible_ssh_host | container_types |
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+
| aio1_keystone_container-ae0ac134            | False    | keystone            | aio1          | None           | 172.29.236.226   | None            |
| aio1_keystone_container-b9f01dae            | False    | keystone            | aio1          | None           | 172.29.238.217   | None            |
| aio1_keystone_container-eeba68bd            | False    | keystone            | aio1          | None           | 172.29.237.8     | None            |
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+

Now we'll use '-r' to remove one of those containers, and then use -l again to see that it's gone:

# scripts/inventory-manage.py -f /etc/rpc_deploy/rpc_inventory.json -r aio1_keystone_container-ae0ac134
Success. . .
# scripts/inventory-manage.py -f /etc/rpc_deploy/rpc_inventory.json -l|egrep 'container_name|^\+|keystone'
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+
| container_name                              | is_metal | component           | physical_host | tunnel_address | ansible_ssh_host | container_types |
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+
| aio1_keystone_container-b9f01dae            | False    | keystone            | aio1          | None           | 172.29.238.217   | None            |
| aio1_keystone_container-eeba68bd            | False    | keystone            | aio1          | None           | 172.29.237.8     | None            |
+---------------------------------------------+----------+---------------------+---------------+----------------+------------------+-----------------+

Perfect - now the inventory doesn't have a reference to it. However, the container itself is still running, so...

####Step 3 destroy the container

First let's see that it's really running. From the above command to interrogate the inventory before we removed it, we can see that the container in this case is running on a host called aio1, so we'll run our ansible commands targeted at that host:

# cd ${BASE}/rpc_deployment
# ansible aio1 -m shell -a 'lxc-ls|grep keystone'
aio1 | success | rc=0 >>
aio1_keystone_container-ae0ac134
aio1_keystone_container-b9f01dae
aio1_keystone_container-eeba68bd

As you can see, even though we've removed it from the config and the inventory, it's still physically running. Time to destroy!

# ansible aio1 -m lxc -a 'name=aio1_keystone_container-ae0ac134 command=destroy'
aio1 | success >> {
    "changed": true
}

And check that it's really gone:

# ansible aio1 -m shell -a 'lxc-ls|grep keystone'
aio1 | success | rc=0 >>
aio1_keystone_container-b9f01dae
aio1_keystone_container-eeba68bd

Woohoo! We killed a container.

NB breakdown of that killer ansible one-liner

-m lxc: use the ansible lxc module
-a 'name=aio1_keystone_container-ae0ac134 command=destroy': pass it the additional params it needs - in this case we're calling the destroy command, and telling it the name of the container to destroy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment