forked from openstack/openstack-ansible-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-setup-swifthosts.yml
110 lines (102 loc) · 3.63 KB
/
test-setup-swifthosts.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
# Copyright 2015, 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: Swift setup
hosts: swift_hosts
# We explicitly do not use 'remote_user: root' here because the
# role totally fails when we do due to not being able to update
# the apt cache when trying to install packages for the ironic
# role.
# TODO(odyssey4me):
# Figure out whether this issue happens for normal (non localhost)
# delegation, and how to resolve the issue.
become: True
gather_facts: true
any_errors_fatal: true
vars_files:
- test-vars.yml
tasks:
- name: Ensure xfsprogs is installed on localhost
package:
name: xfsprogs
state: present
# NOTE(hwoarang) Use the ansible_pkg_mgr fact gathered by
# the setup module for the container because package manager
# detection does not work as expected when the task is delegated.
# The reason is that the package module expects hostvars['%s']['ansible_pkg_mgr']
# to be populated on delegated tasks but this is not the case here
# because we haven't run the setup module on localhost.
use: "{{ ansible_pkg_mgr }}"
delegate_to: "{{ physical_host }}"
run_once: true
- name: Ensure xfsprogs is installed on containers
package:
name: xfsprogs
state: present
- name: Openstack directory Create
file:
state: directory
path: "/openstack/{{ item }}"
with_items:
- 'swift1'
- 'swift2'
- name: Create sparse Swift files
command: "truncate -s 1024G /opt/{{container_name}}_{{ item }}.img"
args:
creates: "/opt/{{ container_name}}_{{ item }}.img"
with_items:
- 'swift1'
- 'swift2'
register: swift_create
delegate_to: "{{ physical_host }}"
- name: Format the Swift files
filesystem:
fstype: xfs
opts: '-K'
dev: "/opt/{{ container_name}}_{{ item }}.img"
when: swift_create is changed
with_items:
- 'swift1'
- 'swift2'
delegate_to: "{{ physical_host }}"
- name: Create the Swift fstab entries and mount the file systems
mount:
name: "/srv/{{ container_name }}_{{ item }}"
src: "/opt/{{ container_name }}_{{ item }}.img"
fstype: xfs
opts: 'loop,noatime,nodiratime,nobarrier,logbufs=8'
passno: 0
dump: 0
state: mounted
with_items:
- 'swift1'
- 'swift2'
register: mount_status
until: mount_status is success
retries: 5
delay: 2
delegate_to: "{{ physical_host }}"
- name: Swift extra lxc config
lxc_container:
name: "{{ container_name }}"
container_config:
- "lxc.mount.entry=/srv/{{ container_name }}_swift1 openstack/swift1 none bind 0 0"
- "lxc.mount.entry=/srv/{{ container_name }}_swift2 openstack/swift2 none bind 0 0"
delegate_to: "{{ physical_host }}"
- name: Wait for container connectivity
wait_for_connection:
connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}"
delay: "{{ lxc_container_wait_params.delay | default(omit) }}"
sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}"
timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}"