Browse Source

Deploy Docker via Ansible and not Puppet

Deploy Docker with Ansible instead of Puppet so later we will be able
to prepare the registry before deploying any containerized service
and do tasks in the middle like updating containers.

Remove the Puppet run from update_tasks, we'll move these tasks later in
ansible-role-container-registry.

Change-Id: Iee0e08cd48f173a39a6f3a1ea54b29e370d4f334
tags/9.0.0.0b3
Emilien Macchi 1 year ago
parent
commit
00f5019ef2
2 changed files with 75 additions and 83 deletions
  1. 23
    10
      puppet/services/docker-registry.yaml
  2. 52
    73
      puppet/services/docker.yaml

+ 23
- 10
puppet/services/docker-registry.yaml View File

@@ -30,6 +30,13 @@ parameters:
30 30
     default: {}
31 31
     description: Parameters specific to the role
32 32
     type: json
33
+  LocalContainerRegistry:
34
+    default: ''
35
+    description: The IP address used to bind the local container registry
36
+    type: string
37
+
38
+conditions:
39
+  local_container_registry_is_empty: {equals : [{get_param: LocalContainerRegistry}, '']}
33 40
 
34 41
 outputs:
35 42
   role_data:
@@ -37,21 +44,27 @@ outputs:
37 44
     value:
38 45
       service_name: docker_registry
39 46
       config_settings:
40
-        tripleo::profile::base::docker_registry::registry_host:
41
-          str_replace:
42
-             template:
43
-               "%{hiera('$NETWORK')}"
44
-             params:
45
-               $NETWORK: {get_param: [ServiceNetMap, DockerRegistryNetwork]}
46
-        tripleo::profile::base::docker_registry::registry_port:
47
-          {get_param: [EndpointMap, DockerRegistryInternal, port]}
48 47
         tripleo.docker_registry.firewall_rules:
49 48
           '155 docker-registry':
50 49
             dport:
51 50
               - 8787
52 51
               - 13787
53
-      step_config: |
54
-        include ::tripleo::profile::base::docker_registry
52
+      step_config: ''
53
+      host_prep_tasks: []
54
+      deploy_steps_tasks:
55
+        - name: Install, Configure and Run Docker Distribution
56
+          when: step|int == 1
57
+          vars:
58
+            container_registry_host:
59
+              if:
60
+              - local_container_registry_is_empty
61
+              - {get_param: [EndpointMap, DockerRegistryInternal, host]}
62
+              - {get_param: LocalContainerRegistry}
63
+            container_registry_port: {get_param: [EndpointMap, DockerRegistryInternal, port]}
64
+          block:
65
+          - include_role:
66
+              name: container-registry
67
+              tasks_from: docker-distribution
55 68
       upgrade_tasks:
56 69
         - name: Install docker packages on upgrade if missing
57 70
           when: step|int == 3

+ 52
- 73
puppet/services/docker.yaml View File

@@ -66,92 +66,71 @@ parameters:
66 66
 
67 67
 conditions:
68 68
   insecure_registry_is_empty: {equals : [{get_param: DockerInsecureRegistryAddress}, []]}
69
-  insecure_registry_mirror_is_empty: {equals : [{get_param: DockerRegistryMirror}, '']}
70 69
   service_debug_unset: {equals : [{get_param: DockerDebug}, '']}
71
-  deployment_user_is_empty: {equals : [{get_param: DeploymentUser}, '']}
72
-  additional_sockets_is_empty: {equals : [{get_param: DockerAdditionalSockets}, []]}
73 70
 
74 71
 outputs:
75 72
   role_data:
76 73
     description: Role data for the docker service
77 74
     value:
78 75
       service_name: docker
79
-      config_settings:
80
-        map_merge:
81
-          - tripleo::profile::base::docker::configure_network: true
82
-            tripleo::profile::base::docker::network_options: "--bip=172.31.0.1/24"
83
-            tripleo::profile::base::docker::docker_options: {get_param: DockerOptions}
84
-            tripleo::profile::base::docker::debug:
76
+      config_settings: {}
77
+      step_config: ''
78
+      host_prep_tasks: []
79
+      deploy_steps_tasks:
80
+        - name: Install, Configure and Run Docker
81
+          when: step|int == 1
82
+          vars:
83
+            container_registry_debug:
85 84
               if:
86 85
                 - service_debug_unset
87 86
                 - {get_param: Debug }
88 87
                 - {get_param: DockerDebug}
89
-          -
90
-            if:
91
-            - insecure_registry_is_empty
92
-            - {}
93
-            - tripleo::profile::base::docker::insecure_registries: {get_param: DockerInsecureRegistryAddress}
94
-          -
95
-            if:
96
-            - insecure_registry_mirror_is_empty
97
-            - {}
98
-            - tripleo::profile::base::docker::registry_mirror: {get_param: DockerRegistryMirror}
99
-          -
100
-            if:
101
-            - deployment_user_is_empty
102
-            - {}
103
-            - tripleo::profile::base::docker::deployment_user: {get_param: DeploymentUser}
104
-          -
105
-            if:
106
-            - additional_sockets_is_empty
107
-            - {}
108
-            - tripleo::profile::base::docker::additional_sockets: {get_param: DockerAdditionalSockets}
109
-      step_config: |
110
-        include ::tripleo::profile::base::docker
88
+            container_registry_deployment_user: {get_param: DeploymentUser}
89
+            container_registry_docker_options: {get_param: DockerOptions}
90
+            container_registry_additional_sockets: {get_param: DockerAdditionalSockets}
91
+            container_registry_insecure_registries:
92
+              if:
93
+                - insecure_registry_is_empty
94
+                - []
95
+                - {get_param: DockerInsecureRegistryAddress}
96
+            container_registry_mirror: {get_param: DockerRegistryMirror}
97
+            container_registry_network_options: '--bip=172.31.0.1/24'
98
+          block:
99
+          - include_role:
100
+              name: container-registry
101
+              tasks_from: docker
102
+      service_config_settings:
103
+        neutron_l3:
104
+          docker_additional_sockets: {get_param: DockerAdditionalSockets}
105
+        neutron_dhcp:
106
+          docker_additional_sockets: {get_param: DockerAdditionalSockets}
111 107
       upgrade_tasks:
112 108
         - name: Install docker packages on upgrade if missing
113 109
           when: step|int == 3
114 110
           yum: name=docker state=latest
115 111
       update_tasks:
116
-        block:
117
-          - name: Detect if puppet on the docker profile would restart the service
118
-            # Note that due to https://tickets.puppetlabs.com/browse/PUP-686 --noop
119
-            # always exits 0, so we cannot rely on that to detect if puppet is going to change stuff
120
-            shell: |
121
-              puppet apply --noop --summarize --detailed-exitcodes --verbose \
122
-                --modulepath /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules \
123
-                --color=false -e "class { 'tripleo::profile::base::docker': step => 1, }" 2>&1 | \
124
-              awk -F ":" '/Out of sync:/ { print $2}'
125
-            register: puppet_docker_noop_output
126
-            failed_when: false
127
-          - name: Is docker going to be updated
128
-            shell: yum check-update docker
129
-            register: docker_check_update
130
-            failed_when: docker_check_update.rc not in [0, 100]
131
-            changed_when: docker_check_update.rc == 100
132
-          - name: Set docker_rpm_needs_update fact
133
-            set_fact: docker_rpm_needs_update={{ docker_check_update.rc == 100 }}
134
-          - name: Set puppet_docker_is_outofsync fact
135
-            set_fact: puppet_docker_is_outofsync={{ puppet_docker_noop_output.stdout|trim|int >= 1 }}
136
-          - name: Stop all containers
137
-            # xargs is preferable to docker stop $(docker ps -q) as that might generate a
138
-            # a too long command line
139
-            shell: docker ps -q | xargs --no-run-if-empty -n1 docker stop
140
-            when: puppet_docker_is_outofsync or docker_rpm_needs_update
141
-          - name: Stop docker
142
-            service:
143
-              name: docker
144
-              state: stopped
145
-            when: puppet_docker_is_outofsync or docker_rpm_needs_update
146
-          - name: Update the docker package
147
-            yum: name=docker state=latest update_cache=yes # cache for tripleo/+bug/1703830
148
-            when: docker_rpm_needs_update
149
-          - name: Apply puppet which will start the service again
150
-            shell: |
151
-              puppet apply --detailed-exitcodes --verbose \
152
-                --modulepath  /etc/puppet/modules:/opt/stack/puppet-modules:/usr/share/openstack-puppet/modules \
153
-                -e "class { 'tripleo::profile::base::docker': step => 1, }"
154
-            register: puppet_docker_apply
155
-            failed_when: puppet_docker_apply.rc not in [0, 2]
156
-            changed_when: puppet_docker_apply.rc == 2
157
-        when: step|int == 2
112
+        - name: Restart Docker when needed
113
+          when: step|int == 2
114
+          block:
115
+            # TODO(emilien)
116
+            # This block will move to ansible-role-container-registry
117
+            - name: Is docker going to be updated
118
+              shell: yum check-update docker
119
+              register: docker_check_update
120
+              failed_when: docker_check_update.rc not in [0, 100]
121
+              changed_when: docker_check_update.rc == 100
122
+            - name: Set docker_rpm_needs_update fact
123
+              set_fact: docker_rpm_needs_update={{ docker_check_update.rc == 100 }}
124
+            - name: Stop all containers
125
+              # xargs is preferable to docker stop $(docker ps -q) as that might generate a
126
+              # a too long command line
127
+              shell: docker ps -q | xargs --no-run-if-empty -n1 docker stop
128
+              when: docker_rpm_needs_update
129
+            - name: Stop docker
130
+              service:
131
+                name: docker
132
+                state: stopped
133
+              when: docker_rpm_needs_update
134
+            - name: Update the docker package
135
+              yum: name=docker state=latest update_cache=yes # cache for tripleo/+bug/1703830
136
+              when: docker_rpm_needs_update

Loading…
Cancel
Save