diff --git a/meta/main.yml b/meta/main.yml index a50c032..0569f1a 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -18,11 +18,12 @@ galaxy_info: description: Installation and setup of molteniron company: IBM license: Apache2 - min_ansible_version: 2.0 + min_ansible_version: 2.2 platforms: - name: Ubuntu versions: - trusty + - xenial categories: - cloud - python diff --git a/tasks/main.yml b/tasks/main.yml index 1a1b286..fea6817 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -25,9 +25,17 @@ tags: - always +- include: molteniron_pre_install.yml + tags: + - molteniron-install + - include: molteniron_install.yml + tags: + - molteniron-install + +- include: molteniron_post_install.yml when: - molteniron_baremetal_nodes is defined - molteniron_baremetal_nodes | length > 0 tags: - - molteniron-install + - molteniron-config diff --git a/tasks/molteniron_install.yml b/tasks/molteniron_install.yml index 75ffb89..3263a9b 100644 --- a/tasks/molteniron_install.yml +++ b/tasks/molteniron_install.yml @@ -13,13 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include: molteniron_install_apt.yml - static: no - when: ansible_pkg_mgr == 'apt' +- name: Install distro packages + package: + name: "{{ molteniron_distro_packages }}" + state: "{{ molteniron_package_state }}" + update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}" + cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 -- include: molteniron_install_yum.yml - static: no - when: ansible_pkg_mgr == 'yum' +- name: Install developer mode distro packages + package: + name: "{{ molteniron_developer_mode_distro_packages }}" + state: "{{ molteniron_package_state }}" + update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}" + cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(cache_timeout, omit) }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + when: + - molteniron_developer_mode | bool - name: Install required pip packages pip: @@ -85,89 +101,3 @@ when: - not molteniron_developer_mode | bool - molteniron_get_venv | changed or molteniron_venv_dir | changed - -- name: Modify molteniron configuration yaml - shell: | - . {{ molteniron_bin }}/activate - - CONF=$(python -c 'from pkg_resources import resource_filename; print resource_filename("molteniron", "conf.yaml");') - - sudo sed -r -i -e 's/^(sqlPass:).*$/\1 "{{ molteniron_container_mysql_password }}"/' ${CONF} - when: "{{ install_molteniron }}" - -- name: authorize openstack_citest MYSQL access - mysql_user: - login_user: root - login_password: "{{ molteniron_container_mysql_password }}" - check_implicit_admin: yes - name: openstack_citest - password: "{{ molteniron_container_mysql_password }}" - priv: "*.*:ALL,GRANT" - state: present - -- name: start molteniron server - shell: | - . {{ molteniron_bin }}/activate - RUNNING=0 - PID_FILE={{ moltenirond_pid_file }} - if [ -f ${PID_FILE} ] - then - # If there is a pid file then see if the server responds to a command - molteniron --output=result status --type=human > /dev/null - if [ $? -eq 0 ] - then - RUNNING=1 - fi - fi - if [ ${RUNNING} -eq 0 ] - then - # If there is a pid file, delete it because the helper will try and use it - test -f ${PID_FILE} && sudo rm ${PID_FILE} - moltenirond-helper start - fi - when: "{{ install_molteniron }}" - -- name: add molteniron nodes - shell: | - . {{ molteniron_bin }}/activate - - NAME={{ item.name }} - IPMI_IP={{ item.ipmi_ip }} - IPMI_USER={{ item.ipmi_user }} - IPMI_PASSWORD={{ item.ipmi_password }} - ALLOCATION_POOL={{ item.allocation_pool }} - PORT_HWADDR={{ item.port_hwaddr }} - CPU_ARCH={{ item.cpu_arch }} - CPUS={{ item.cpus }} - RAM_MB={{ item.ram_mb }} - DISK_GB={{ item.disk_gb }} - - FOUND=0 - while read LINE - do - EXISTING_NAME=$(echo ${LINE} | cut -f2 -d,) - if [ "${EXISTING_NAME}" == "${NAME}" ] - then - FOUND=1 - fi - done < <(molteniron --output=result status --type csv) - - if [ ${FOUND} -eq 0 ] - then - molteniron add_baremetal \ - ${NAME} \ - ${IPMI_IP} \ - ${IPMI_USER} \ - ${IPMI_PASSWORD} \ - ${ALLOCATION_POOL} \ - ${PORT_HWADDR} \ - ${CPU_ARCH} \ - ${CPUS} \ - ${RAM_MB} \ - ${DISK_GB} - fi - args: - # Note: we need while/do/done < <() redirection support - executable: /bin/bash - with_items: "{{ molteniron_baremetal_nodes }}" - when: "{{ install_molteniron }}" diff --git a/tasks/molteniron_install_apt.yml b/tasks/molteniron_install_apt.yml deleted file mode 100644 index 7b33924..0000000 --- a/tasks/molteniron_install_apt.yml +++ /dev/null @@ -1,45 +0,0 @@ ---- -# Copyright (c) 2017 IBM Corporation. -# -# 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: Update apt sources - apt: - update_cache: yes - cache_valid_time: 600 - register: apt_update - until: apt_update|success - retries: 5 - delay: 2 - -- name: Install apt packages - apt: - pkg: "{{ item }}" - state: "{{ molteniron_package_state }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ molteniron_distro_packages }}" - -- name: Install developer mode apt packages - apt: - pkg: "{{ item }}" - state: "{{ molteniron_package_state }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ molteniron_developer_mode_distro_packages }}" - when: - - molteniron_developer_mode | bool diff --git a/tasks/molteniron_post_install.yml b/tasks/molteniron_post_install.yml new file mode 100644 index 0000000..b8325fe --- /dev/null +++ b/tasks/molteniron_post_install.yml @@ -0,0 +1,100 @@ +--- +# Copyright (c) 2017 IBM Corporation. +# +# 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: Modify molteniron configuration yaml + shell: | + . {{ molteniron_bin }}/activate + + CONF=$(python -c 'from pkg_resources import resource_filename; print resource_filename("molteniron", "conf.yaml");') + + sudo sed -r -i -e 's/^(sqlPass:).*$/\1 "{{ molteniron_container_mysql_password }}"/' ${CONF} + changed_when: true + +- name: authorize openstack_citest MYSQL access + mysql_user: + login_user: root + login_password: "{{ molteniron_container_mysql_password }}" + check_implicit_admin: yes + name: openstack_citest + password: "{{ molteniron_container_mysql_password }}" + priv: "*.*:ALL,GRANT" + state: present + +- name: start molteniron server + shell: | + . {{ molteniron_bin }}/activate + RUNNING=0 + PID_FILE={{ moltenirond_pid_file }} + if [ -f ${PID_FILE} ] + then + # If there is a pid file then see if the server responds to a command + molteniron --output=result status --type=human > /dev/null + if [ $? -eq 0 ] + then + RUNNING=1 + fi + fi + if [ ${RUNNING} -eq 0 ] + then + # If there is a pid file, delete it because the helper will try and use it + test -f ${PID_FILE} && sudo rm ${PID_FILE} + moltenirond-helper start + fi + changed_when: true + +- name: add molteniron nodes + shell: | + . {{ molteniron_bin }}/activate + + NAME={{ item.name }} + IPMI_IP={{ item.ipmi_ip }} + IPMI_USER={{ item.ipmi_user }} + IPMI_PASSWORD={{ item.ipmi_password }} + ALLOCATION_POOL={{ item.allocation_pool }} + PORT_HWADDR={{ item.port_hwaddr }} + CPU_ARCH={{ item.cpu_arch }} + CPUS={{ item.cpus }} + RAM_MB={{ item.ram_mb }} + DISK_GB={{ item.disk_gb }} + + FOUND=0 + while read LINE + do + EXISTING_NAME=$(echo ${LINE} | cut -f2 -d,) + if [ "${EXISTING_NAME}" == "${NAME}" ] + then + FOUND=1 + fi + done < <(molteniron --output=result status --type csv) + + if [ ${FOUND} -eq 0 ] + then + molteniron add_baremetal \ + ${NAME} \ + ${IPMI_IP} \ + ${IPMI_USER} \ + ${IPMI_PASSWORD} \ + ${ALLOCATION_POOL} \ + ${PORT_HWADDR} \ + ${CPU_ARCH} \ + ${CPUS} \ + ${RAM_MB} \ + ${DISK_GB} + fi + args: + # Note: we need while/do/done < <() redirection support + executable: /bin/bash + with_items: "{{ molteniron_baremetal_nodes }}" + changed_when: true diff --git a/tasks/molteniron_install_yum.yml b/tasks/molteniron_pre_install.yml similarity index 56% rename from tasks/molteniron_install_yum.yml rename to tasks/molteniron_pre_install.yml index 79bf3ab..d765ebb 100644 --- a/tasks/molteniron_install_yum.yml +++ b/tasks/molteniron_pre_install.yml @@ -13,7 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create molteniron dir +- name: Create the system group + group: + name: "{{ molteniron_system_group_name }}" + state: "present" + system: "yes" + +- name: Create the system user + user: + name: "{{ molteniron_system_user_name }}" + group: "{{ molteniron_system_group_name }}" + comment: "{{ molteniron_system_comment }}" + shell: "{{ molteniron_system_shell }}" + system: "yes" + createhome: "yes" + home: "{{ molteniron_system_user_home }}" + +- name: Create required dirs file: path: "{{ item.path }}" state: directory @@ -21,26 +37,10 @@ group: "{{ item.group|default(molteniron_system_group_name) }}" mode: "{{ item.mode|default('0755') }}" with_items: - - { path: "/var/lock/molteniron", mode: "2755" } - -- name: Install yum packages - yum: - pkg: "{{ item }}" - state: "{{ molteniron_package_state }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ molteniron_distro_packages }}" - -- name: Install developer mode yum packages - yum: - pkg: "{{ item }}" - state: "{{ molteniron_package_state }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ molteniron_developer_mode_distro_packages }}" - when: - - molteniron_developer_mode | bool + - path: "/openstack/venvs" + mode: "0755" + owner: "root" + group: "root" + - path: "{{ molteniron_system_user_home }}" + - path: "/var/lock/molteniron" + mode: "2755" diff --git a/vars/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml index 0d77962..8923102 100644 --- a/vars/ubuntu-14.04.yml +++ b/vars/ubuntu-14.04.yml @@ -28,7 +28,3 @@ molteniron_distro_packages: moltenirond_pid_file: "/var/run/moltenirond.pid" molteniron_source_dir: "/home/ubuntu/molteniron" - -# Hack to get past the following: -# ANSIBLE0012 checks for usage of shell or command without when, changed_when, ... -install_molteniron: true diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml index b413c3d..2d4f544 100644 --- a/vars/ubuntu-16.04.yml +++ b/vars/ubuntu-16.04.yml @@ -39,7 +39,3 @@ molteniron_developer_mode_distro_packages: moltenirond_pid_file: "/var/run/moltenirond.pid" molteniron_source_dir: "/home/ubuntu/molteniron" - -# Hack to get past the following: -# ANSIBLE0012 checks for usage of shell or command without when, changed_when, ... -install_molteniron: true