From 6bb0178f6457d548579e3a657a454074e0d5c7ec Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Thu, 14 Jan 2016 14:04:49 -0800 Subject: [PATCH] Cleanup syntax issues for Ansible 2 compatibility This patch fixes a few syntax issues required for Ansible 2 compatibility that Ansible 1.x was more lenient with. When a 'when' clause is combined with a 'with_*' statement, the clause is processed separately for each item. Tasks with 'when' clauses which depended on an item variable being defined have either applied a default empty value to the item or a new task individual task has been created for each item in the loop. Tasks within the os-cinder-install playboook have been updated to loop through cinder_backends as a hash. Change-Id: I9b53eb5dd709a6bed1797961015aa3dd328340f3 --- playbooks/os-cinder-install.yml | 14 +++++----- .../roles/os_cinder/tasks/cinder_backends.yml | 7 +++-- .../os_horizon/tasks/horizon_post_install.yml | 1 - .../tasks/horizon_ssl_user_provided.yml | 26 +++++++++++++------ .../tasks/keystone_ssl_user_provided.yml | 26 +++++++++++++------ .../os_swift_sync/tasks/swift_rings_build.yml | 10 +++---- .../swift_rings_post_distribution_check.yml | 6 ++--- .../tasks/swift_sync_post_install.yml | 5 +++- 8 files changed, 55 insertions(+), 40 deletions(-) diff --git a/playbooks/os-cinder-install.yml b/playbooks/os-cinder-install.yml index 1eeeb56e32..22450de3e6 100644 --- a/playbooks/os-cinder-install.yml +++ b/playbooks/os-cinder-install.yml @@ -32,19 +32,17 @@ - lxc-aa-profile - name: Add volume group block device to cinder shell: | - {% if item.1.volume_group is defined %} - if [ "$(pvdisplay | grep -B1 {{ item.1.volume_group }} | awk '/PV/ {print $3}')" ];then - for device in `pvdisplay | grep -B1 {{ item.1.volume_group }} | awk '/PV/ {print $3}'` + {% if item.value.volume_group is defined %} + if [ "$(pvdisplay | grep -B1 {{ item.value.volume_group }} | awk '/PV/ {print $3}')" ];then + for device in `pvdisplay | grep -B1 {{ item.value.volume_group }} | awk '/PV/ {print $3}'` do lxc-device -n {{ container_name }} add $device done fi {% else %} - echo "{{ item.1 }} volume_group not defined" + echo "{{ item.key }} volume_group not defined" {% endif %} - with_items: cinder_backends|dictsort - when: > - cinder_backends is defined and - physical_host != container_name + with_dict: cinder_backends|default({}) + when: physical_host != container_name delegate_to: "{{ physical_host }}" tags: - cinder-lxc-devices diff --git a/playbooks/roles/os_cinder/tasks/cinder_backends.yml b/playbooks/roles/os_cinder/tasks/cinder_backends.yml index 647d683ad8..5d20cba16b 100644 --- a/playbooks/roles/os_cinder/tasks/cinder_backends.yml +++ b/playbooks/roles/os_cinder/tasks/cinder_backends.yml @@ -27,10 +27,9 @@ - name: Add in cinder devices types shell: | . {{ ansible_env.HOME }}/openrc - {{ cinder_bin }}/cinder type-create "{{ item.0 }}" - {{ cinder_bin }}/cinder type-key "{{ item.0 }}" set volume_backend_name="{{ item.1.volume_backend_name }}" - with_items: cinder_backends|dictsort - when: cinder_backends is defined + {{ cinder_bin }}/cinder type-create "{{ item.key }}" + {{ cinder_bin }}/cinder type-key "{{ item.key }}" set volume_backend_name="{{ item.value.volume_backend_name }}" + with_dict: cinder_backends|default({}) tags: - cinder-backends - cinder-backends-types diff --git a/playbooks/roles/os_horizon/tasks/horizon_post_install.yml b/playbooks/roles/os_horizon/tasks/horizon_post_install.yml index d81752661a..4411d13a56 100644 --- a/playbooks/roles/os_horizon/tasks/horizon_post_install.yml +++ b/playbooks/roles/os_horizon/tasks/horizon_post_install.yml @@ -53,7 +53,6 @@ src: "{{ item.value.src }}" dest: "{{ horizon_lib_dir }}/openstack_dashboard/static/dashboard/{{ item.value.dest }}" with_dict: "{{ horizon_custom_uploads | default({}) }}" - when: horizon_custom_uploads is defined tags: - horizon-branding diff --git a/playbooks/roles/os_horizon/tasks/horizon_ssl_user_provided.yml b/playbooks/roles/os_horizon/tasks/horizon_ssl_user_provided.yml index b64607acca..0a49991ee0 100644 --- a/playbooks/roles/os_horizon/tasks/horizon_ssl_user_provided.yml +++ b/playbooks/roles/os_horizon/tasks/horizon_ssl_user_provided.yml @@ -13,17 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Drop user provided ssl cert and key +- name: Drop user provided ssl cert copy: - src: "{{ item.src }}" - dest: "{{ item.dest }}" + src: "{{ horizon_user_ssl_cert }}" + dest: "{{ horizon_ssl_cert }}" owner: "root" group: "root" - mode: "{{ item.mode }}" - with_items: - - { src: "{{ horizon_user_ssl_cert }}", dest: "{{ horizon_ssl_cert }}", mode: "0644" } - - { src: "{{ horizon_user_ssl_key }}", dest: "{{ horizon_ssl_key }}", mode: "0640" } - when: horizon_user_ssl_cert is defined and horizon_user_ssl_key is defined + mode: "0644" + when: horizon_user_ssl_cert is defined + notify: Restart apache2 + tags: + - horizon-configs + - horizon-ssl + +- name: Drop user provided ssl key + copy: + src: "{{ horizon_user_ssl_key }}" + dest: "{{ horizon_ssl_key }}" + owner: "root" + group: "root" + mode: "0640" + when: horizon_user_ssl_key is defined notify: Restart apache2 tags: - horizon-configs diff --git a/playbooks/roles/os_keystone/tasks/keystone_ssl_user_provided.yml b/playbooks/roles/os_keystone/tasks/keystone_ssl_user_provided.yml index 1828dc81f7..e0f7a6fbd7 100644 --- a/playbooks/roles/os_keystone/tasks/keystone_ssl_user_provided.yml +++ b/playbooks/roles/os_keystone/tasks/keystone_ssl_user_provided.yml @@ -13,17 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Drop user provided ssl cert and key +- name: Drop user provided ssl cert copy: - src: "{{ item.src }}" - dest: "{{ item.dest }}" + src: "{{ keystone_user_ssl_cert }}" + dest: "{{ keystone_ssl_cert }}" owner: "root" group: "root" - mode: "{{ item.mode }}" - with_items: - - { src: "{{ keystone_user_ssl_cert }}", dest: "{{ keystone_ssl_cert }}", mode: "0644" } - - { src: "{{ keystone_user_ssl_key }}", dest: "{{ keystone_ssl_key }}", mode: "0640" } - when: keystone_user_ssl_cert is defined and keystone_user_ssl_key is defined + mode: "0644" + when: keystone_user_ssl_cert is defined + notify: Restart Apache + tags: + - keystone-configs + - keystone-ssl + +- name: Drop user provided ssl key + copy: + src: "{{ keystone_user_ssl_key }}" + dest: "{{ keystone_ssl_key }}" + owner: "root" + group: "root" + mode: "0640" + when: keystone_user_ssl_key is defined notify: Restart Apache tags: - keystone-configs diff --git a/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml index bfde6a1ca9..f1b0de37e9 100644 --- a/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_build.yml @@ -31,8 +31,8 @@ owner: "{{ swift_system_user_name }}" group: "{{ swift_system_group_name }}" with_items: - - { item: "{{ swift.account }}", port: "{{ swift_account_port }}", type: "account" } - - { item: "{{ swift.container }}", port: "{{ swift_container_port}}", type: "container" } + - { item: "{{ swift.account | default({}) }}", port: "{{ swift_account_port }}", type: "account" } + - { item: "{{ swift.container | default({}) }}", port: "{{ swift_container_port}}", type: "container" } tags: - swift-rings - swift-rings-contents @@ -68,8 +68,7 @@ command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" with_nested: - [ 'account', 'container' ] - - swift_managed_regions - when: swift_managed_regions is defined + - swift_managed_regions | default([]) sudo: yes sudo_user: "{{ swift_system_user_name }}" args: @@ -95,8 +94,7 @@ command: "/usr/bin/python /etc/swift/scripts/swift_rings.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" with_nested: - "{{ swift.storage_policies }}" - - swift_managed_regions - when: swift_managed_regions is defined + - swift_managed_regions | default([]) sudo: yes sudo_user: "{{ swift_system_user_name }}" args: diff --git a/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml index d0b906cb85..039df6f76d 100644 --- a/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_rings_post_distribution_check.yml @@ -61,8 +61,7 @@ command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/{{ item[0] }}.contents -r {{ item[1] }}" with_nested: - [ 'account', 'container' ] - - swift_managed_regions - when: swift_managed_regions is defined + - swift_managed_regions | default([]) sudo: yes sudo_user: "{{ swift_system_user_name }}" args: @@ -88,8 +87,7 @@ command: "/usr/bin/python /etc/swift/scripts/swift_rings_check.py -f /etc/swift/scripts/object-{{ item[0].policy.index }}.contents -r {{ item[1] }}" with_nested: - "{{ swift.storage_policies }}" - - swift_managed_regions - when: swift_managed_regions is defined + - swift_managed_regions | default([]) sudo: yes sudo_user: "{{ swift_system_user_name }}" args: diff --git a/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml b/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml index b55373743a..5b626ef977 100644 --- a/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml +++ b/playbooks/roles/os_swift_sync/tasks/swift_sync_post_install.yml @@ -18,7 +18,10 @@ name: "{{ item }}" state: "started" pattern: "{{ item }}" - with_items: swift_account_program_names + swift_container_program_names + swift_object_program_names + with_items: + - "{{ swift_account_program_names }}" + - "{{ swift_container_program_names }}" + - "{{ swift_object_program_names }}" when: inventory_hostname in groups['swift_hosts'] - name: "Ensure services are started"