{"id":4605,"date":"2018-05-06T12:33:24","date_gmt":"2018-05-06T10:33:24","guid":{"rendered":"http:\/\/2d6.fr\/?p=4605"},"modified":"2021-01-14T09:10:28","modified_gmt":"2021-01-14T08:10:28","slug":"linux-ansible-pour-redemarrer-uniquement-les-serveurs-de-type-redhat-mais-pas-les-debians","status":"publish","type":"post","link":"https:\/\/2d6.fr\/?p=4605","title":{"rendered":"[linux] ansible pour red\u00e9marrer uniquement les serveurs de type redhat mais pas les debians"},"content":{"rendered":"<p>J&rsquo;ai une s\u00e9rie de serveurs linux, et j&rsquo;ai besoin d\u2019y ex\u00e9cuter des t\u00e2ches fr\u00e9quentes. la solution sera Ansible. \ud83d\ude09<\/p>\n<h2>Red\u00e9marrage des serveurs linux selon \u00ab\u00a0ansible_os_family\u00a0\u00bb<\/h2>\n<p>Mise \u00e0 jour du fichier d&rsquo;inventaire<\/p>\n<p>J&rsquo;en ai profit\u00e9 pour re cr\u00e9er le fichier d&rsquo;inventaire au format yaml ( ce qui va me permettre une meilleur compatibilit\u00e9 avec des nouvelles commandes, plugins etc.)<\/p>\n<p>\/etc\/ansible\/hosts<\/p>\n<pre>all:\n\n&nbsp; children:\n&nbsp;&nbsp;&nbsp; linux:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; children:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; redhats:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hosts:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rh69:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centos1:\n            (...)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client3:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; debians:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hosts:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client1:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (...)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; supervision:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Xservers:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hosts:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client1:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rh69:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centos1:\n\n&nbsp;&nbsp;&nbsp; windows:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hosts:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; srv-exchange01:\n\n&nbsp;&nbsp;&nbsp; web-servers:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hosts:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client1:\n        (...)\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rh69:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; centos1:<\/pre>\n<h3>Le playbook :<\/h3>\n<p>J&rsquo;aurai p\u00fb m&rsquo;appuyer sur le groupe \u00ab\u00a0redhats\u00a0\u00bb, mais c&rsquo;\u00e9tait l&rsquo;occasion de travailler un peu plus finement.. \ud83d\ude09<\/p>\n<p>reboot-redhatFamily.yml<\/p>\n<pre>- hosts: linux\n&nbsp; tasks:\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - name: test reboot des redhat\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; when: ansible_os_family == \"RedHat\"\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; command: \/sbin\/reboot\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - name: attendre reboot\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; local_action: wait_for host=\"{{ inventory_hostname }}\" search_regex=OpenSSH port=22 timeout=300<\/pre>\n<p>&nbsp;<\/p>\n<p>un petit test :<\/p>\n<p>ansible-playbook reboot-redhatFamily.yml &#8211;list-hosts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; O\u00f9 tous les linux sont list\u00e9s, mais o\u00f9 seuls les redhat et centos seront reboot\u00e9s.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img src=linux20.png>  ansible reboots only redhat family&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[97],"class_list":["post-4605","post","type-post","status-publish","format-standard","hentry","category-application_reseau","category-linux","tag-linux"],"_links":{"self":[{"href":"https:\/\/2d6.fr\/index.php?rest_route=\/wp\/v2\/posts\/4605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2d6.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2d6.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2d6.fr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/2d6.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4605"}],"version-history":[{"count":0,"href":"https:\/\/2d6.fr\/index.php?rest_route=\/wp\/v2\/posts\/4605\/revisions"}],"wp:attachment":[{"href":"https:\/\/2d6.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2d6.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2d6.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}