aboutsummaryrefslogtreecommitdiffstats
path: root/util/docker-compose/roles/cobbler/tasks/main.yml
blob: e3f1308825dd6ef1a3d8a3959e5f356d9c78304a (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
---
- name: copy files
  shell: |
    docker exec compass-cobbler bash -c \
    "cp -rf /root/cobbler/* /var/lib/cobbler/; \
     rm -rf /var/lib/cobbler/conf; \
     cp -rf /root/cobbler/conf/* /etc/cobbler"

- name: chmod migrate_ks.py
  shell: |
    docker exec compass-cobbler bash -c \
    "chmod +x /var/lib/cobbler/triggers/sync/post/migrate_ks.py"

- name: render cobbler files
  template:
    src: "{{ item }}.j2"
    dest: "{{ docker_compose_dir }}/cobbler/{{ item }}"
  with_items:
    - dhcp.template
    - named.template
    - settings
    - zone.template

- name: copy files to /etc/cobbler
  shell: |
    docker cp "{{ docker_compose_dir }}/cobbler/{{ item }}" compass-cobbler:/etc/cobbler
  with_items:
    - dhcp.template
    - named.template
    - settings
    - zone.template

# - name: restart cobblerd service
#   shell: |
#     docker exec compass-cobbler bash -c \
#     "service cobblerd restart"

- name: prepare iso and ppa
  shell: |
    docker cp "{{ compass_dists_dir }}/{{ item.value.iso_name }}.iso" compass-cobbler:/tmp
    docker exec compass-cobbler bash -c \
    "mkdir -p /mnt/{{ item.value.iso_name }}; \
     mount -o loop /tmp/{{ item.value.iso_name }}.iso /mnt/{{ item.value.iso_name }}"
    docker cp "{{ compass_dists_dir }}/{{ item.value.ppa_name }}.tar.gz" compass-cobbler:/tmp
    docker exec compass-cobbler bash -c \
    "mkdir -p /var/lib/cobbler/repo_mirror/{{ item.value.ppa_name }}"
  with_dict: "{{ distros }}"
  run_once: "True"
  ignore_errors: "True"

- name: cobbler import iso
  shell: |
    name=`basename {{ item.value.iso_name }} | \
    sed -e 's/.iso//g' -e 's/-amd64//g' -e 's/-x86_64//g'`
    docker exec compass-cobbler bash -c \
    "service cobblerd restart;
     sleep 3;
     cobbler import --name $name \
                    --path /mnt/{{ item.value.iso_name }} \
                    --arch x86_64 \
                    --kickstart /var/lib/cobbler/kickstarts/{{ item.value.kickstart }} \
                    --breed {{ item.value.breed }}"
  with_dict: "{{ distros }}"
  run_once: "True"
  register: result2
  until: result2.rc == 0
  retries: 10
  delay: 3

- name: add repos
  shell: |
    docker exec compass-cobbler bash -c \
    "cobbler repo add --name {{ item.value.ppa_name }} \
                      --mirror /var/lib/cobbler/repo_mirror/{{ item.value.ppa_name }} \
                      --mirror-locally True \
                      --arch=x86_64 {{ item.value.extra | default()}}"
  with_dict: "{{ distros }}"
  run_once: "True"

- name: edit profiles
  shell: |
    name=`basename {{ item.value.iso_name }} | \
    sed -e 's/.iso//g' -e 's/-amd64//g' -e 's/-x86_64//g'`-x86_64
    docker exec compass-cobbler bash -c \
    "cobbler profile edit --name $name \
                          --name-servers '' \
                          --repos {{ item.value.ppa_name }} \
                          --ksmeta \"tree=http://{{ host_ip }}/cobbler/ks_mirror/$name\" \
                          --kopts \"{{ item.value.kopts | default('') }}\" \
                          --kopts-post \"{{ item.value.kopts_post | default('') }}\""
  with_dict: "{{ distros }}"
  run_once: "True"

- name: cobbler sync
  shell: |
    docker exec compass-cobbler bash -c \
    "cobbler sync"