{"id":2975,"date":"2014-10-21T16:09:40","date_gmt":"2014-10-21T14:09:40","guid":{"rendered":"http:\/\/supportex.net\/blog\/?p=2975"},"modified":"2019-05-10T14:32:39","modified_gmt":"2019-05-10T12:32:39","slug":"ansible-add-swap-linux-box","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/","title":{"rendered":"Ansible: how to add swap memory on your Linux box"},"content":{"rendered":"<p>If you are not familiar with <a href=\"http:\/\/docs.ansible.com\">ansible<\/a>, you might want to take a look at <a href=\"http:\/\/supportex.net\/blog\/2014\/10\/ansible-quick-intro\/\">our previous post<\/a>. \u00a0So here&#8217;s a problem. If you have, say, Amazon EC2 instance or Rackspace Cloud server, you might want to add swap memory. You can do do it by running the following commands:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">sudo dd if=\/dev\/zero of=\/mnt\/4GB.swap bs=4096 count=1048576\nsudo chmod 600 \/mnt\/4GBB.swap\nsudo mkswap \/mnt\/4GB.swap\nswapon \/mnt\/4GB.swap<\/pre>\n<p>and add this line to \/etc\/fstab:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">\/mnt\/512MiB.swap  none  swap  sw  0 0<\/pre>\n<p>If you have one server it&#8217;s acceptable, but if you have a lot of them, it would be much easier \u00a0to use ansible. We will use the <a href=\"http:\/\/www.rackspace.com\/knowledge_center\/article\/create-a-linux-swap-file\">how-to by Rackspace<\/a> on how to create swap file. (We assume you have a user account &#8216;devops&#8217; which is able to log in using SSH key \u00a0as well as to run commands as root via sudo. If need need check our blog entry about ansible mentioned earlier).<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">- hosts: web001\ntasks:\n- name: create the file to be used for swap\ncommand: fallocate -l 4G \/mnt\/4GB.swap\n\n- name: format the file for swap\ncommand: mkswap \/mnt\/4GB.swap\n\n- name: change swap file permissions\nfile: path=\/mnt\/4GB.swap owner=root group=root mode=0600\n\n- name: add the file to the system as a swap file\ncommand: swapon \/mnt\/4GB.swap\n\n- name: write swap entry in fstab\nmount: name=none src=\/mnt\/4GB.swap fstype=swap opts=sw passno=0 dump=0 state=present\n\n<\/pre>\n<p>If you get this error message:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">fallocate: \/mnt\/4GB.swap: fallocate failed: Operation not supported<\/pre>\n<p>use dd instead:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">sudo dd if=\/dev\/zero of=.\/4GB.swap bs=4096 count=1048576<\/code><\/p>\n<p>Run create a swap file run:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">ansible-playbook add_swap.yml -u devops -s  -v --check<\/code><\/p>\n<p>Remove &#8211;check parameter to apply changes. And that&#8217;s it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are not familiar with ansible, you might want to take a look at our previous post. \u00a0So here&#8217;s a problem. If you have, say, Amazon EC2 instance or Rackspace Cloud server, you might want to add swap memory. You can do do it by running the following commands: sudo dd if=\/dev\/zero of=\/mnt\/4GB.swap bs=4096&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[155,275,156],"class_list":["post-2975","post","type-post","status-publish","format-standard","hentry","category-linux","tag-ansible","tag-linux","tag-swap"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-21T14:09:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-10T12:32:39+00:00\" \/>\n<meta name=\"author\" content=\"Oleksii Tykhonov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oleksii Tykhonov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\"},\"author\":{\"name\":\"Oleksii Tykhonov\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"headline\":\"Ansible: how to add swap memory on your Linux box\",\"datePublished\":\"2014-10-21T14:09:40+00:00\",\"dateModified\":\"2019-05-10T12:32:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\"},\"wordCount\":168,\"commentCount\":0,\"keywords\":[\"ansible\",\"linux\",\"swap\"],\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\",\"url\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\",\"name\":\"Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2014-10-21T14:09:40+00:00\",\"dateModified\":\"2019-05-10T12:32:39+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"description\":\"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ansible: how to add swap memory on your Linux box\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\",\"name\":\"Oleksii Tykhonov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"caption\":\"Oleksii Tykhonov\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog","description":"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/","og_locale":"en_US","og_type":"article","og_title":"Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog","og_description":"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.","og_url":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/","og_site_name":"Supportex.NET blog","article_published_time":"2014-10-21T14:09:40+00:00","article_modified_time":"2019-05-10T12:32:39+00:00","author":"Oleksii Tykhonov","twitter_misc":{"Written by":"Oleksii Tykhonov","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/"},"author":{"name":"Oleksii Tykhonov","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"headline":"Ansible: how to add swap memory on your Linux box","datePublished":"2014-10-21T14:09:40+00:00","dateModified":"2019-05-10T12:32:39+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/"},"wordCount":168,"commentCount":0,"keywords":["ansible","linux","swap"],"articleSection":["linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/","url":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/","name":"Ansible: how to add swap memory on your Linux box &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2014-10-21T14:09:40+00:00","dateModified":"2019-05-10T12:32:39+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"description":"How to add swap memory on your Linux box wih Ansible. Ansible add swap memory.","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2014\/10\/ansible-add-swap-linux-box\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"Ansible: how to add swap memory on your Linux box"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251","name":"Oleksii Tykhonov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","caption":"Oleksii Tykhonov"},"url":"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=2975"}],"version-history":[{"count":7,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2975\/revisions"}],"predecessor-version":[{"id":3120,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2975\/revisions\/3120"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=2975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=2975"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=2975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}