{"id":7319,"date":"2018-04-06T08:52:44","date_gmt":"2018-04-06T00:52:44","guid":{"rendered":"http:\/\/rmohan.com\/?p=7319"},"modified":"2018-04-06T08:52:44","modified_gmt":"2018-04-06T00:52:44","slug":"how-to-use-sysctl-with-ansible-2","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7319","title":{"rendered":"how to use sysctl with ansible"},"content":{"rendered":"<p>[root@localhost ~]# <strong>sysctl -a |grep vm.swappiness<\/strong><br \/>\nvm.swappiness = 30<\/p>\n<p>[root@localhost ~]# <strong>ansible-galaxy init sysctl<\/strong><br \/>\n\u2013 sysctl was created successfully<\/p>\n<p>[root@localhost ~]#<strong> ansible-doc sysctl<\/strong><\/p>\n<p>[root@localhost ~]# <strong>vim <span class=\"skimlinks-unlinked\">test.yml<\/span><\/strong><br \/>\n\u2014<br \/>\n\u2013 hosts: localhost<br \/>\nroles:<br \/>\n\u2013 sysctl<br \/>\nvars:<br \/>\nsysctl_settings:<br \/>\n\u2013 name: vm.swappiness<br \/>\nvalue: 90<\/p>\n<p>[root@localhost ~]# <strong>vim sysctl\/tasks\/<span class=\"skimlinks-unlinked\">main.yml<\/span> <\/strong><br \/>\n\u2014<br \/>\n# tasks file for sysctl<br \/>\n\u2013 name: sysctl settings<br \/>\nsysctl:<br \/>\nname: \u201c{{ <span class=\"skimlinks-unlinked\">item.name<\/span> }}\u201d<br \/>\nvalue: \u201c{{ <span class=\"skimlinks-unlinked\">item.value<\/span> }}\u201d<br \/>\nreload: true<br \/>\nstate: \u201c{{ <span class=\"skimlinks-unlinked\">item.state<\/span> | default(\u2018present\u2019) }}\u201d<br \/>\nwith_items: \u201c{{ sysctl_settings }}\u201d<\/p>\n<p>[root@localhost ~]# <strong>ansible-playbook <span class=\"skimlinks-unlinked\">test.yml<\/span><\/strong><\/p>\n<p>PLAY [localhost] *******************************************************************************************************************************<\/p>\n<p>TASK [Gathering Facts] *************************************************************************************************************************<br \/>\nok: [localhost]<\/p>\n<p>TASK [sysctl : sysctl settings] ****************************************************************************************************************<br \/>\nchanged: [localhost] =&gt; (item={u\u2019state\u2019: u\u2019present\u2019, u\u2019name\u2019: u\u2019vm.swappiness\u2019, u\u2019value\u2019: 90})<\/p>\n<p>PLAY RECAP *************************************************************************************************************************************<br \/>\nlocalhost : ok=2 changed=1 unreachable=0 failed=0<\/p>\n<p>[root@localhost ~]# <strong>sysctl -a |grep vm.swappiness<\/strong><br \/>\nvm.swappiness = 90<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[root@localhost ~]# sysctl -a |grep vm.swappiness vm.swappiness = 30<\/p>\n<p>[root@localhost ~]# ansible-galaxy init sysctl \u2013 sysctl was created successfully<\/p>\n<p>[root@localhost ~]# ansible-doc sysctl<\/p>\n<p>[root@localhost ~]# vim test.yml \u2014 \u2013 hosts: localhost roles: \u2013 sysctl vars: sysctl_settings: \u2013 name: vm.swappiness value: 90<\/p>\n<p>[root@localhost ~]# vim sysctl\/tasks\/main.yml \u2014 # tasks file for sysctl \u2013 name: sysctl settings [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[91],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7319"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7319"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7319\/revisions"}],"predecessor-version":[{"id":7320,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7319\/revisions\/7320"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}