Cleanup directory creation tasks

Using the realpath filter, we can idempotently create/modify
the log directory whether it is a symlink or not. This allows
us to consolidate two tasks into the common directory creation
task.

The extra task to create the images directory can be consolidated
into the same common directory creation task.

We also convert the items list to yaml dictionary format to
match the desired style according to the style guide.

Change-Id: I46e8b7c3be005681efc8a520318e7945c9c9a259
This commit is contained in:
Jesse Pretorius 2018-05-13 18:37:30 +01:00
parent 0d4ea81077
commit 4aedfc612d
1 changed files with 22 additions and 45 deletions

View File

@ -50,55 +50,32 @@
mode: "0755"
with_items: "{{ glance_nfs_client }}"
- name: Create glance dir
- name: Create glance directories
file:
path: "{{ item.path }}"
path: "{{ item.path | realpath }}"
state: directory
owner: "{{ item.owner|default(glance_system_user_name) }}"
group: "{{ item.group|default(glance_system_group_name) }}"
mode: "{{ item.mode|default(omit) }}"
owner: "{{ item.owner | default(glance_system_user_name) }}"
group: "{{ item.group | default(glance_system_group_name) }}"
mode: "{{ item.mode | default(omit) }}"
when:
- item.path not in glance_mount_points
- "item.path not in glance_mount_points"
with_items:
- { path: "/openstack", mode: "0755", owner: "root", group: "root" }
- { path: "/etc/glance", mode: "0750" }
- { path: "/var/cache/glance" }
- { path: "{{ glance_system_user_home }}" }
- { path: "{{ glance_system_user_home }}/cache/api", mode: "0700" }
- { path: "{{ glance_system_user_home }}/cache/registry" }
- { path: "{{ glance_system_user_home }}/scrubber" }
- name: Create glance images dir
file:
path: "{{ glance_system_user_home }}/images/"
state: directory
owner: "{{ glance_system_user_name }}"
group: "{{ glance_system_group_name }}"
mode: "0755"
when:
- glance_system_user_home + '/images' not in glance_mount_points
- name: Test for log directory or link
shell: |
if [ -h "/var/log/glance" ]; then
chown -h {{ glance_system_user_name }}:{{ glance_system_group_name }} "/var/log/glance"
chown -R {{ glance_system_user_name }}:{{ glance_system_group_name }} "$(readlink /var/log/glance)"
else
exit 1
fi
register: log_dir
failed_when: false
changed_when: log_dir.rc != 0
- name: Create glance log dir
file:
path: "/var/log/glance"
state: directory
owner: "{{ glance_system_user_name }}"
group: "{{ glance_system_group_name }}"
mode: "0755"
when:
- log_dir.rc != 0
- path: "/openstack"
mode: "0755"
owner: "root"
group: "root"
- path: "/etc/glance"
mode: "0750"
- path: "/var/cache/glance"
- path: "{{ glance_system_user_home }}"
- path: "{{ glance_system_user_home }}/cache/api"
mode: "0700"
- path: "{{ glance_system_user_home }}/cache/registry"
- path: "{{ glance_system_user_home }}/scrubber"
- path: "{{ glance_system_user_home }}/images"
mode: "0755"
- path: "/var/log/glance"
mode: "0755"
- name: Install distro packages
package: