-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add swap module #5241
Comments
Could be an extension to the mount module |
yes, it could. We're welcome to take submissions but I'm not going to keep this tracker ticket open to keep the queue a little bit less cluttered. Someone can implement if they like. Thanks! |
Anyone aware of someone creating this? I'm also in need for it and starting to figure out my own tasks to handle it for now. |
for anyone else coming across this thread, I ended up with this: ...
- name: Create swap space
command: dd if=/dev/zero of=/extraswap bs=1M count=512
when: ansible_swaptotal_mb < 1
- name: Make swap
command: mkswap /extraswap
when: ansible_swaptotal_mb < 1
- name: Add to fstab
action: lineinfile dest=/etc/fstab regexp="extraswap" line="/extraswap none swap sw 0 0" state=present
- name: Turn swap on
command: swapon -a
- name: Set swapiness
shell: echo 0 | sudo tee /proc/sys/vm/swappiness
... |
@scottmotte Just used this myself, very helpful, thanks!! |
@scottmotte Thanks for the swap role, I just made a role of this with a variable called swap_mb |
@samos123 woot. Thanks. |
@scottmotte Is this snippet idempotent? |
@eaignerThe first two commands have the the when clause, and the 3rd uses a special command to only add the line when it doesn't exist. The last two commands will always run, but should harmless, so fairly indempotent. |
Oh... I didn't realize |
Swappiness should be permanently set using the sysctl module IMO:
Also, setting it to 0 seems to disable swap so I'd set it to 1 to have minimum swappiness. |
I reused some of the snippets and adjusted them. |
@JensDebergh Here's my swap role which checks whether the swap file already exists: https://gist.github.com/manuelmeurer/a2c0a8c24a0bb5092250 |
@manuelmeurer Awesome thanks ! 👍 |
There are two ways to create swap, on In some aws ec2 instances, we can use ephemeral storage as swap space. But this ansible playbook has to be added to cronjob, otherwise, if the instance is stop/start, the swap setting will disappear. Here are the codes I did with logic volume created from disk device
|
Your way works, which @manuelmeurer 's way is not idempotent with my way to set swap on logic volume |
@SydOps I'm pretty sure my script is idempotent. Can you explain? |
Sorry for the misunderstand, I didn't test your way
The first when condition works fine, not the second. |
I don't fully understand what your problem is but it seems it has nothing to do with the code I posted. Maybe a general confusion on your side how the |
Following up on some comments regarding checking swapfile presence with "stat" module: strongly suggest using the following params on the "stat" module to make checking much faster (1 second vs. 45 seconds to check a 10GB file):
|
There should be an idempotent way to ensure a swapfile is created and enabled.
The text was updated successfully, but these errors were encountered: