{"id":123,"date":"2025-06-23T10:20:06","date_gmt":"2025-06-23T08:20:06","guid":{"rendered":"https:\/\/blog.cp2i.com\/?p=123"},"modified":"2025-06-23T10:20:06","modified_gmt":"2025-06-23T08:20:06","slug":"rollout-restart-dun-deployment-avec-ansible","status":"publish","type":"post","link":"https:\/\/blog.cp2i.com\/index.php\/2025\/06\/23\/rollout-restart-dun-deployment-avec-ansible\/","title":{"rendered":"Rollout restart d&rsquo;un deployment avec Ansible"},"content":{"rendered":"\n<p>Dans ce billet, nous aborderons une m\u00e9thode pour op\u00e9rer un rollout restart avec Ansible.<\/p>\n\n\n\n<p>Pour ce faire, nous allons jouer avec les annotations du deployment pour y ajouter un cl\u00e9 \u00ab\u00a0restartedAt\u00a0\u00bb avec la date du jour en valeur.<\/p>\n\n\n\n<p>Voici le module en question:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">- name: Patch coredns configmap to handle the DNS server\n  <span class=\"hljs-attr\">delegate_to<\/span>: localhost\n  <span class=\"hljs-attr\">run_once<\/span>: <span class=\"hljs-literal\">true<\/span>\n  kubernetes.core.k8s:\n    kubeconfig: <span class=\"hljs-string\">\"\/etc\/rancher\/rke2\/rke2.yaml\"<\/span>\n    <span class=\"hljs-attr\">namespace<\/span>: kube-system\n    <span class=\"hljs-attr\">template<\/span>:\n      path: rke2-coredns.yml.j2\n  <span class=\"hljs-attr\">register<\/span>: coredns_change_dns\n\n- name: Patch coredns deploy to force restart\n  <span class=\"hljs-attr\">delegate_to<\/span>: localhost\n  <span class=\"hljs-attr\">run_once<\/span>: <span class=\"hljs-literal\">true<\/span>\n  kubernetes.core.k8s:\n    kubeconfig: <span class=\"hljs-string\">\"\/etc\/rancher\/rke2\/rke2.yaml\"<\/span>\n    <span class=\"hljs-attr\">state<\/span>: patched\n    <span class=\"hljs-attr\">kind<\/span>: Deployment\n    <span class=\"hljs-attr\">namespace<\/span>: kube-system\n    <span class=\"hljs-attr\">name<\/span>: rke2-coredns\n    <span class=\"hljs-attr\">definition<\/span>:\n      spec:\n        template:\n          metadata:\n            annotations:\n              kubectl.kubernetes.io\/restartedAt: <span class=\"hljs-string\">\"{{ now(fmt='%Y-%m-%dT%H:%M:%SZ') }}\"<\/span>\n  <span class=\"hljs-attr\">when<\/span>: coredns_change_dns.changed<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Langage du code\u00a0:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Nous utilisons donc ici le state <em>patched<\/em> du <em>kubernetes.core.k8s<\/em> pour g\u00e9n\u00e9rer une erreur dans le cas o\u00f9 le deployment n&rsquo;existerait pas.<\/p>\n\n\n\n<p>Et voil\u00e0, votre deployment red\u00e9marrera quand la configuration sera chang\u00e9e \u00e0 l&rsquo;\u00e9tape pr\u00e9c\u00e9dente.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dans ce billet, nous aborderons une m\u00e9thode pour op\u00e9rer un rollout restart avec Ansible. Pour ce faire, nous allons jouer avec les annotations du deployment pour y ajouter un cl\u00e9 \u00ab\u00a0restartedAt\u00a0\u00bb avec la date du jour en valeur. Voici le module en question: Nous utilisons donc ici le state patched du kubernetes.core.k8s pour g\u00e9n\u00e9rer une [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_regular_price":[],"currency_symbol":[],"footnotes":""},"categories":[18,20,19],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-ansible","category-automatisation","category-kubernetes"],"post_slider_layout_featured_media_urls":{"thumbnail":"","post_slider_layout_landscape_large":"","post_slider_layout_portrait_large":"","post_slider_layout_square_large":"","post_slider_layout_landscape":"","post_slider_layout_portrait":"","post_slider_layout_square":"","full":""},"_links":{"self":[{"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":3,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":126,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/posts\/123\/revisions\/126"}],"wp:attachment":[{"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cp2i.com\/index.php\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}