From aa38052400978b17569e472a7c6b6405e5d926c2 Mon Sep 17 00:00:00 2001 From: Pavlo Shchelokovskyy Date: Mon, 5 Dec 2016 14:57:12 +0000 Subject: [PATCH] DRY when installing components collect source/git info into a list and use it via `with_items` when cloning/local copying sources. Also, use git module with appropriate arguments instead of calling git 4 times through command module. Change-Id: Ia0be4b64b849cac1c32da02b2492ce026233d8b7 --- .../defaults/main.yml | 30 ++++++++++++ .../bifrost-prep-for-install/tasks/git.yml | 26 ---------- .../tasks/git_download.yaml | 49 ------------------- .../tasks/local_path.yaml | 35 ------------- .../bifrost-prep-for-install/tasks/main.yml | 12 ++++- 5 files changed, 40 insertions(+), 112 deletions(-) delete mode 100644 playbooks/roles/bifrost-prep-for-install/tasks/git.yml delete mode 100644 playbooks/roles/bifrost-prep-for-install/tasks/git_download.yaml delete mode 100644 playbooks/roles/bifrost-prep-for-install/tasks/local_path.yaml diff --git a/playbooks/roles/bifrost-prep-for-install/defaults/main.yml b/playbooks/roles/bifrost-prep-for-install/defaults/main.yml index acd983fd9..1146eddaf 100644 --- a/playbooks/roles/bifrost-prep-for-install/defaults/main.yml +++ b/playbooks/roles/bifrost-prep-for-install/defaults/main.yml @@ -29,3 +29,33 @@ reqs_git_branch: master # Conditional variables utilized based on CI or manual testing options. copy_from_local_path: false ci_testing_zuul: false + +bifrost_install_sources: + - git_folder: "{{ ironic_git_folder }}" + git_url: "{{ ironic_git_url }}" + git_branch: "{{ ironic_git_branch }}" + name: ironic + - git_folder: "{{ ironicclient_git_folder }}" + git_url: "{{ ironicclient_git_url }}" + git_branch: "{{ ironicclient_git_branch }}" + name: ironicclient + - git_folder: "{{ shade_git_folder }}" + git_url: "{{ shade_git_url }}" + git_branch: "{{ shade_git_branch }}" + name: shade + - git_folder: "{{ dib_git_folder }}" + git_url: "{{ dib_git_url }}" + git_branch: "{{ dib_git_branch }}" + name: dib + - git_folder: "{{ ironicinspector_git_folder }}" + git_url: "{{ ironicinspector_git_url }}" + git_branch: "{{ ironicinspector_git_branch }}" + name: ironicinspector + - git_folder: "{{ ironicinspectorclient_git_folder }}" + git_url: "{{ ironicinspectorclient_git_url }}" + git_branch: "{{ ironicinspectorclient_git_branch }}" + name: ironicinspectorclient + - git_folder: "{{ reqs_git_folder }}" + git_url: "{{ reqs_git_url }}" + git_branch: "{{ reqs_git_branch }}" + name: requirements diff --git a/playbooks/roles/bifrost-prep-for-install/tasks/git.yml b/playbooks/roles/bifrost-prep-for-install/tasks/git.yml deleted file mode 100644 index 16abd6fa3..000000000 --- a/playbooks/roles/bifrost-prep-for-install/tasks/git.yml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. -# -# 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: "Clone repository" - command: git clone {{ git_url }} {{ git_folder }} chdir={{ git_root }} creates={{ git_folder }} - -- name: "Check out branch" - command: git checkout -f {{ git_branch }} chdir={{ git_folder }} - -- name: "Reset local repository" - command: git reset --hard {{ git_branch }} chdir={{ git_folder }} - -- name: "Resync local repository" - command: git pull --ff-only chdir={{ git_folder }} diff --git a/playbooks/roles/bifrost-prep-for-install/tasks/git_download.yaml b/playbooks/roles/bifrost-prep-for-install/tasks/git_download.yaml deleted file mode 100644 index 5c199fdb7..000000000 --- a/playbooks/roles/bifrost-prep-for-install/tasks/git_download.yaml +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. -# -# 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. ---- -- include: git.yml - git_url="{{ ironic_git_url }}" - git_folder="{{ ironic_git_folder }}" - git_branch="{{ ironic_git_branch }}" - -- include: git.yml - git_url="{{ ironicclient_git_url }}" - git_folder="{{ ironicclient_git_folder }}" - git_branch="{{ ironicclient_git_branch }}" - -- include: git.yml - git_url="{{ shade_git_url }}" - git_folder="{{ shade_git_folder }}" - git_branch="{{ shade_git_branch }}" - -- include: git.yml - git_url="{{ dib_git_url }}" - git_folder="{{ dib_git_folder }}" - git_branch="{{ dib_git_branch }}" - -- include: git.yml - git_url="{{ ironicinspector_git_url }}" - git_folder="{{ ironicinspector_git_folder }}" - git_branch="{{ ironicinspector_git_branch }}" - -- include: git.yml - git_url="{{ ironicinspectorclient_git_url }}" - git_folder="{{ ironicinspectorclient_git_folder }}" - git_branch="{{ ironicinspectorclient_git_branch }}" - -- include: git.yml - git_url="{{ reqs_git_url }}" - git_folder="{{ reqs_git_folder }}" - git_branch="{{ reqs_git_branch }}" diff --git a/playbooks/roles/bifrost-prep-for-install/tasks/local_path.yaml b/playbooks/roles/bifrost-prep-for-install/tasks/local_path.yaml deleted file mode 100644 index 7ab8392e8..000000000 --- a/playbooks/roles/bifrost-prep-for-install/tasks/local_path.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. -# -# 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: "ironic - Copy into place" - command: cp -a {{ ironic_git_url }} {{ ironic_git_folder }} chdir={{ git_root }} creates={{ ironic_git_folder }} - -- name: "python-ironicclient - Copy into place" - command: cp -a {{ ironicclient_git_url }} {{ ironicclient_git_folder }} chdir={{ git_root }} creates={{ ironicclient_git_folder }} - -- name: "Shade - Copy into place" - command: cp -a {{ shade_git_url }} {{ shade_git_folder }} chdir={{ git_root }} creates={{ shade_git_folder }} - -- name: "Disk Image Builder - Copy into place" - command: cp -a {{ dib_git_url }} {{ dib_git_folder }} chdir={{ git_root }} creates={{ dib_git_folder }} - -- name: "ironic-inspector - Copy into place" - command: cp -a {{ ironicinspector_git_url }} {{ ironicinspector_git_folder }} chdir={{ git_root }} creates={{ ironicinspector_git_folder }} - -- name: "python-ironic-inspector-client - Copy into place" - command: cp -a {{ ironicinspectorclient_git_url }} {{ ironicinspectorclient_git_folder }} chdir={{ git_root }} creates={{ ironicinspectorclient_git_folder }}i - -- name: "Clone upper requirements" - command: cp -a {{ reqs_git_url }} {{ reqs_git_folder }} chdir={{ git_root }} creates={{ reqs_git_folder }} diff --git a/playbooks/roles/bifrost-prep-for-install/tasks/main.yml b/playbooks/roles/bifrost-prep-for-install/tasks/main.yml index 036900d9f..9429860ee 100644 --- a/playbooks/roles/bifrost-prep-for-install/tasks/main.yml +++ b/playbooks/roles/bifrost-prep-for-install/tasks/main.yml @@ -21,9 +21,17 @@ group: "{{ ansible_user_gid }}" - name: "Download via GIT" - include: git_download.yaml + git: + dest: "{{ item.git_folder }}" + force: yes + repo: "{{ item.git_url }}" + version: "{{ item.git_branch }}" + update: yes + clone: yes + with_items: "{{ bifrost_install_sources }}" when: ci_testing_zuul | bool == false and copy_from_local_path | bool == false - name: "Copy from local path" - include: local_path.yaml + command: cp -a {{ item.git_url }} {{ item.git_folder }} creates={{ item.git_folder }} + with_items: "{{ bifrost_install_sources }}" when: ci_testing_zuul | bool == true or copy_from_local_path | bool == true