aboutsummaryrefslogtreecommitdiffstats
path: root/util/docker-compose/roles/compass/tasks/main.yml
blob: 46a413b894185c8f3561e6e3e1aefaac6fc30f35 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
- include_vars: "{{ item }}"
  with_first_found:
    - "{{ compass_dists_dir }}/build-{{ ansible_architecture }}.yaml"
    - "{{ compass_dists_dir }}/build.yaml"

- set_fact:
    image_name: "{{ item.name | regex_replace('-', '_') }}"
    image_repo: "{{ item.url }}"
  with_items: "{{ packages }}"
  when: item.name in compose_images
  register: compass_images

- name: generate compose_images.yml
  copy:
    dest: "{{ compass_dists_dir }}/compose_images.yml"
    content: |
      {% set image_dict = {} %}
      {% for item in compass_images.results %}
      {% if "ansible_facts" in item %}
      {% set facts = item.ansible_facts %}
      {% set _ = image_dict.update({facts.image_name: facts.image_repo}) %}
      {% endif %}
      {% endfor %}
      {% for key in image_dict %}
      {{ key }}: {{ image_dict[key] }}
      {% endfor %}

- include_vars: "{{ compass_dists_dir }}/compose_images.yml"

- name: get jumphost ip
  shell: |
    external_nic=`ip route |grep '^default'|awk '{print $5F}'|sed -n '1p'`
    host_ip=`ifconfig $external_nic | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
    echo $host_ip
  register: external_ip

- name: fix name.service
  shell: |
    if [ ! -f "/etc/apparmor.d/disable/usr.sbin.named" ]; then
        ln -s /etc/apparmor.d/usr.sbin.named /etc/apparmor.d/disable/
        apparmor_parser -R /etc/apparmor.d/usr.sbin.named
    fi

- name: render docker-compose file
  template:
    src: docker-compose.yml.j2
    dest: "{{ docker_compose_dir }}/docker-compose.yml"

- name: docker-compose down
  shell: docker-compose down
  args:
    chdir: "{{ docker_compose_dir }}"

- name: load docker images
  shell: |
    images=$(ls "{{ compass_dists_dir }}" | grep .*.tar)
    for image in $images
    do
        docker load -i "{{ compass_dists_dir }}/$image"
    done

- name: copy files
  shell:
    cp -rf "{{ item }}" "{{ docker_compose_dir }}"
  with_items:
    - "{{ compass_dir }}/deploy/adapters/ansible"
    - "{{ compass_dir }}/deploy/compass_conf"
    - "{{ compass_dir }}/deploy/adapters/cobbler"

- name: retrieve plugins list
  command: "ls {{ compass_dir }}/plugins/"
  register: plugin_list

- name: copy plugins roles
  copy:
    src: "{{ compass_dir }}/plugins/{{ item }}/roles/"
    dest: "{{ docker_compose_dir }}/ansible/roles/"
  with_items: "{{ plugin_list.stdout_lines }}"
  when: item != 'template'

- name: chmod directory
  file:
    dest: "{{ item }}"
    mode: 0755
  with_items:
    - "{{ compass_dir }}/deploy/adapters/ansible"
    - "{{ compass_dir }}/deploy/compass_conf"
    - "{{ compass_dir }}/deploy/adapters/cobbler"

- name: copy ansible scripts into ansible folder
  shell: |
    for i in `ls "{{ docker_compose_dir }}/ansible" | grep "openstack_"`; do
        cp -rf "{{ docker_compose_dir }}"/ansible/openstack/* \
             "{{ docker_compose_dir }}"/ansible/$i
    done

- name: copy ansible plugins
  copy:
    src: "{{ compass_dir }}/deploy/ansible_plugins"
    dest: "{{ docker_compose_dir }}"

- name: create run dir
  file:
    path: "{{ docker_compose_dir }}/ansible/run"
    state: directory

- name: render cobbler
  template:
    src: "{{ item }}.j2"
    dest: "{{ docker_compose_dir }}/compass_conf/os_installer/{{ item }}"
  with_items:
    - cobbler.conf

- name: docker-compose up
  shell: docker-compose up -d
  args:
    chdir: "{{ docker_compose_dir }}"

- name: create compass db tables
  shell: |
    sleep 3; \
    docker exec compass-deck bash -c "/opt/compass/bin/manage_db.py createdb"
  register: result1
  until: result1.rc == 0
  retries: 10
  delay: 2
  tags:
    - redploy

- name: rm ansible run
  shell: |
    docker exec compass-tasks bash -c "rm -rf /var/ansible/run/*"

- name: start httpd service
  shell: |
    docker exec compass-deck bash -c "systemctl start httpd"