diff --git a/doc/source/developer-docs/quickstart-aio.rst b/doc/source/developer-docs/quickstart-aio.rst index 1629f8be82..e68977e3c0 100644 --- a/doc/source/developer-docs/quickstart-aio.rst +++ b/doc/source/developer-docs/quickstart-aio.rst @@ -110,6 +110,24 @@ a space between each set of options, for example: $ export BOOTSTRAP_OPTS="bootstrap_host_data_disk_device=sdb" $ export BOOTSTRAP_OPTS="${BOOTSTRAP_OPTS} bootstrap_host_ubuntu_repo=http://mymirror.example.com/ubuntu" +You may wish to change the role fetch mode. Options are "galaxy" and +"git-clone". The default for this option is "galaxy". + +options: + :galaxy: Resolve all role dependencies using the ``ansible-galaxy`` resolver + :git-clone: Clone all of the role dependencies using native git + +Notes: + When doing role development it may be useful to set ``ANSIBLE_ROLE_FETCH_MODE`` + to *git-clone*. This will provide you the ability to develop roles within the + environment by modifying, patching, or committing changes using an intact + git tree while the *galaxy* option scrubs the ``.git`` directory when + it resolves a dependency. + + .. code-block:: bash + + $ export ANSIBLE_ROLE_FETCH_MODE=git-clone + The next step is to bootstrap Ansible and the Ansible roles for the development environment. Deployers can customize roles by adding variables to override the defaults in each role (see :ref:`adding-galaxy-roles`). Run the diff --git a/releasenotes/notes/ansible-role-fetch-mode-cd163877e96d504a.yaml b/releasenotes/notes/ansible-role-fetch-mode-cd163877e96d504a.yaml new file mode 100644 index 0000000000..c01968760a --- /dev/null +++ b/releasenotes/notes/ansible-role-fetch-mode-cd163877e96d504a.yaml @@ -0,0 +1,5 @@ +--- +features: + - A new option has been added to ``bootstrap-ansible.sh`` to set + the role fetch mode. The environment variable ``ANSIBLE_ROLE_FETCH_MODE`` + sets how role dependencies are resolved. diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index cf85df126d..da653db083 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -28,7 +28,8 @@ export ANSIBLE_ROLE_FILE=${ANSIBLE_ROLE_FILE:-"ansible-role-requirements.yml"} export ANSIBLE_WORKING_DIR=${ANSIBLE_WORKING_DIR:-/opt/ansible_${ANSIBLE_GIT_RELEASE}} export SSH_DIR=${SSH_DIR:-"/root/.ssh"} export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-"noninteractive"} - +# Set the role fetch mode to any option [galaxy, git-clone] +export ANSIBLE_ROLE_FETCH_MODE=${ANSIBLE_ROLE_FETCH_MODE:-galaxy} ## Functions ----------------------------------------------------------------- info_block "Checking for required libraries." 2> /dev/null || @@ -38,6 +39,9 @@ info_block "Checking for required libraries." 2> /dev/null || ## Main ---------------------------------------------------------------------- info_block "Bootstrapping System with Ansible" +# Set the variable to the role file to be the absolute path +ANSIBLE_ROLE_FILE="$(readlink -f ${ANSIBLE_ROLE_FILE})" + # Create the ssh dir if needed ssh_key_create @@ -92,10 +96,21 @@ fi $PIP_COMMAND install $PIP_OPTS "${ANSIBLE_WORKING_DIR}" || $PIP_COMMAND install --isolated $PIP_OPTS "${ANSIBLE_WORKING_DIR}" # Update dependent roles -if [ -f "${ANSIBLE_ROLE_FILE}" ];then +if [ -f "${ANSIBLE_ROLE_FILE}" ]; then + if [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'galaxy' ]];then # Pull all required roles. - ansible-galaxy install --role-file=${ANSIBLE_ROLE_FILE} \ + ansible-galaxy install --role-file="${ANSIBLE_ROLE_FILE}" \ --force + elif [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'git-clone' ]];then + pushd tests + ansible-playbook -i "localhost ansible-connection=local," \ + get-ansible-role-requirements.yml \ + -e role_file="${ANSIBLE_ROLE_FILE}" + popd + else + echo "Please set the ANSIBLE_ROLE_FETCH_MODE to either of the following options ['galaxy', 'git-clone']" + exit 99 + fi fi # Create openstack ansible wrapper tool diff --git a/scripts/gate-check-commit.sh b/scripts/gate-check-commit.sh index 7a98e9fffd..ec4ee91571 100755 --- a/scripts/gate-check-commit.sh +++ b/scripts/gate-check-commit.sh @@ -27,6 +27,8 @@ export BOOTSTRAP_OPTS=${BOOTSTRAP_OPTS:-''} # This variable is being added to ensure the gate job executes an exit # function at the end of the run. export OSA_GATE_JOB=true +# Set the role fetch mode to any option [galaxy, git-clone] +export ANSIBLE_ROLE_FETCH_MODE="git-clone" ## Functions ----------------------------------------------------------------- info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh diff --git a/tests/get-ansible-role-requirements.yml b/tests/get-ansible-role-requirements.yml new file mode 100644 index 0000000000..fe81dac920 --- /dev/null +++ b/tests/get-ansible-role-requirements.yml @@ -0,0 +1,43 @@ +--- +# Copyright 2016, Rackspace US, Inc. +# +# 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 the role ansible-role-requirements + hosts: localhost + connection: local + user: root + tasks: + - name: Remove target directory if required + shell: | + if [[ ! -d "{{ item.path | default('/etc/ansible/roles') }}/{{ item.name | default(item.src | basename) }}/.git" ]]; then + rm -rf "{{ item.path | default('/etc/ansible/roles') }}/{{ item.name | default(item.src | basename) }}" + fi + args: + executable: /bin/bash + when: + - item.scm == "git" or item.scm is undefined + with_items: "{{ roles }}" + - name: Clone git repos + git: + repo: "{{ item.src }}" + dest: "{{ item.path | default('/etc/ansible/roles') }}/{{ item.name | default(item.src | basename) }}" + version: "{{ item.version | default('master') }}" + update: true + force: true + when: + - item.scm == "git" or item.scm is undefined + with_items: "{{ roles }}" + vars: + roles: "{{ lookup('file', role_file) | from_yaml }}" + role_file: '../ansible-role-requirements.yml' \ No newline at end of file