Use package module to install distro packages
Consolidate distro package install tasks into a single task using the package module and pass the package list into the name instead of using a with_items loop. The minimum Ansible version is raised to 2.2 due to a known bug [1] in Ansible's apt module which does not update the cache properly if the cache update and the install are combined in a single task. [1] https://github.com/ansible/ansible-modules-core/issues/1497 Also: - split install tasks into pre-install, install and post-install tasks and tag them appropriately. Change-Id: I0c5cc16ba1d82b7fd169156d1890c86614210cad
This commit is contained in:
parent
a80e50d65a
commit
879c1db7cf
|
@ -18,11 +18,12 @@ galaxy_info:
|
||||||
description: Installation and setup of molteniron
|
description: Installation and setup of molteniron
|
||||||
company: IBM
|
company: IBM
|
||||||
license: Apache2
|
license: Apache2
|
||||||
min_ansible_version: 2.0
|
min_ansible_version: 2.2
|
||||||
platforms:
|
platforms:
|
||||||
- name: Ubuntu
|
- name: Ubuntu
|
||||||
versions:
|
versions:
|
||||||
- trusty
|
- trusty
|
||||||
|
- xenial
|
||||||
categories:
|
categories:
|
||||||
- cloud
|
- cloud
|
||||||
- python
|
- python
|
||||||
|
|
|
@ -25,9 +25,17 @@
|
||||||
tags:
|
tags:
|
||||||
- always
|
- always
|
||||||
|
|
||||||
|
- include: molteniron_pre_install.yml
|
||||||
|
tags:
|
||||||
|
- molteniron-install
|
||||||
|
|
||||||
- include: molteniron_install.yml
|
- include: molteniron_install.yml
|
||||||
|
tags:
|
||||||
|
- molteniron-install
|
||||||
|
|
||||||
|
- include: molteniron_post_install.yml
|
||||||
when:
|
when:
|
||||||
- molteniron_baremetal_nodes is defined
|
- molteniron_baremetal_nodes is defined
|
||||||
- molteniron_baremetal_nodes | length > 0
|
- molteniron_baremetal_nodes | length > 0
|
||||||
tags:
|
tags:
|
||||||
- molteniron-install
|
- molteniron-config
|
||||||
|
|
|
@ -13,13 +13,29 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- include: molteniron_install_apt.yml
|
- name: Install distro packages
|
||||||
static: no
|
package:
|
||||||
when: ansible_pkg_mgr == 'apt'
|
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
|
- name: Install developer mode distro packages
|
||||||
static: no
|
package:
|
||||||
when: ansible_pkg_mgr == 'yum'
|
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
|
- name: Install required pip packages
|
||||||
pip:
|
pip:
|
||||||
|
@ -85,89 +101,3 @@
|
||||||
when:
|
when:
|
||||||
- not molteniron_developer_mode | bool
|
- not molteniron_developer_mode | bool
|
||||||
- molteniron_get_venv | changed or molteniron_venv_dir | changed
|
- 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 }}"
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
|
@ -13,7 +13,23 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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:
|
file:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
@ -21,26 +37,10 @@
|
||||||
group: "{{ item.group|default(molteniron_system_group_name) }}"
|
group: "{{ item.group|default(molteniron_system_group_name) }}"
|
||||||
mode: "{{ item.mode|default('0755') }}"
|
mode: "{{ item.mode|default('0755') }}"
|
||||||
with_items:
|
with_items:
|
||||||
- { path: "/var/lock/molteniron", mode: "2755" }
|
- path: "/openstack/venvs"
|
||||||
|
mode: "0755"
|
||||||
- name: Install yum packages
|
owner: "root"
|
||||||
yum:
|
group: "root"
|
||||||
pkg: "{{ item }}"
|
- path: "{{ molteniron_system_user_home }}"
|
||||||
state: "{{ molteniron_package_state }}"
|
- path: "/var/lock/molteniron"
|
||||||
register: install_packages
|
mode: "2755"
|
||||||
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
|
|
|
@ -28,7 +28,3 @@ molteniron_distro_packages:
|
||||||
moltenirond_pid_file: "/var/run/moltenirond.pid"
|
moltenirond_pid_file: "/var/run/moltenirond.pid"
|
||||||
|
|
||||||
molteniron_source_dir: "/home/ubuntu/molteniron"
|
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
|
|
||||||
|
|
|
@ -39,7 +39,3 @@ molteniron_developer_mode_distro_packages:
|
||||||
moltenirond_pid_file: "/var/run/moltenirond.pid"
|
moltenirond_pid_file: "/var/run/moltenirond.pid"
|
||||||
|
|
||||||
molteniron_source_dir: "/home/ubuntu/molteniron"
|
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
|
|
||||||
|
|
Loading…
Reference in New Issue