From bc21adddac233a9fb18336cf6c830c45b685cc7d Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Thu, 21 Apr 2016 13:49:57 -0400 Subject: [PATCH] Template /etc/environment rather than use lineinfile The existing lineinfile implementation is buggy when changing and removing entries from the global_environment_variables dict Change-Id: Ic9899b1a4a72e72d0bac26eb8f650681186332e1 Partial-Bug: #1573131 --- tasks/openstack_proxy_settings.yml | 9 ++++----- templates/environment.j2 | 10 ++++++++++ tests/test.yml | 16 ++++++++++------ 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 templates/environment.j2 diff --git a/tasks/openstack_proxy_settings.yml b/tasks/openstack_proxy_settings.yml index d761ef28..deec406c 100644 --- a/tasks/openstack_proxy_settings.yml +++ b/tasks/openstack_proxy_settings.yml @@ -14,10 +14,9 @@ # limitations under the License. - name: Install host proxy settings - lineinfile: - dest: /etc/environment - state: present - line: "{% if item.value %}{{ item.key }}={{ item.value }}{% endif %}" - with_dict: global_environment_variables |default({}) + template: + dest: "/etc/environment" + src: "environment.j2" + mode: "0644" tags: - openstack-host-proxies diff --git a/templates/environment.j2 b/templates/environment.j2 new file mode 100644 index 00000000..37f7bc76 --- /dev/null +++ b/templates/environment.j2 @@ -0,0 +1,10 @@ +# {{ ansible_managed }} + +PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" +{% if global_environment_variables %} +{% for key, value in global_environment_variables.iteritems() %} +{% if value %} +{{ key }}={{ value }} +{% endif %} +{% endfor %} +{% endif %} \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml index d513f52b..f386d937 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -27,7 +27,8 @@ openstack_kernel_options: - { key: 'vm.swappiness', value: 5 } global_environment_variables: - PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" + http_proxy: "http://someproxy.example.com" + https_proxy: "https://someproxy.example.com" post_tasks: - name: Open modules file slurp: @@ -41,11 +42,16 @@ slurp: src: /etc/hosts register: hosts_file + - name: Open /etc/environment file + slurp: + src: /etc/environment + register: environment_file - name: Read files set_fact: modules_content: "{{ modules_file.content | b64decode }}" sysctl_content: "{{ sysctl_file.content | b64decode }}" hosts_content: "{{ hosts_file.content | b64decode }}" + environment_content: "{{ environment_file.content | b64decode }}" - name: Check for release file stat: path: /etc/openstack-release @@ -54,10 +60,6 @@ stat: path: /etc/default/sysstat register: systat_file - - name: Check for environment file - stat: - path: /etc/environment - register: environment_file - name: Check for ssh dir stat: path: "{{ ansible_env.HOME}}/.ssh" @@ -71,5 +73,7 @@ - "'127.111.111.102 test2' in hosts_content" - "release_file.stat.exists" - "systat_file.stat.exists" - - "environment_file.stat.exists" + - "'/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games' in environment_content" + - "'http_proxy=http://someproxy.example.com' in environment_content" + - "'https_proxy=https://someproxy.example.com' in environment_content" - "ssh_dir.stat.isdir"