summaryrefslogtreecommitdiff
path: root/cloud/lxc
diff options
context:
space:
mode:
authorEvgeni Golov <evgeni@golov.de>2016-04-10 13:37:00 +0200
committerEvgeni Golov <evgeni@golov.de>2016-04-10 13:37:00 +0200
commit8db3a639837e836dd02030c5177301bb699e5de7 (patch)
tree3b8dc8beccf509d1bd61063eb5bf00b3578f175e /cloud/lxc
parentc03e77a63a37ac7ab9ad12c3e42e633547aa1688 (diff)
downloadansible-modules-extras-8db3a639837e836dd02030c5177301bb699e5de7.tar.gz
fix handling of config options that share the same prefix
container_config: - "lxc.network.ipv4.gateway=auto" - "lxc.network.ipv4=192.0.2.1" might try to override lxc.network.ipv4.gateway in the second entry as both start with "lxc.network.ipv4". use a regular expression to find a line that contains (optional) whitespace and an = after the key. Signed-off-by: Evgeni Golov <evgeni@golov.de>
Diffstat (limited to 'cloud/lxc')
-rw-r--r--cloud/lxc/lxc_container.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/cloud/lxc/lxc_container.py b/cloud/lxc/lxc_container.py
index 3cbff331..d19101dd 100644
--- a/cloud/lxc/lxc_container.py
+++ b/cloud/lxc/lxc_container.py
@@ -424,6 +424,8 @@ lxc_container:
sample: True
"""
+import re
+
try:
import lxc
except ImportError:
@@ -748,9 +750,10 @@ class LxcContainerManagement(object):
key = key.strip()
value = value.strip()
new_entry = '%s = %s\n' % (key, value)
+ keyre = re.compile(r'%s(\s+)?=' % key)
for option_line in container_config:
# Look for key in config
- if option_line.startswith(key):
+ if keyre.match(option_line):
_, _value = option_line.split('=', 1)
config_value = ' '.join(_value.split())
line_index = container_config.index(option_line)