Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding an fstab option using Ansible

I am trying to add nodev to my /etc/fstab file. I am using the Ansible command below but with no luck. My issue lies with the regular expression, I'm not a pro at regex.

- name: Add nodev to /etc/fstab
  lineinfile:
    dest=/etc/fstab
    backup=yes
    backrefs=yes
    state=present
    regexp='(^/dev[\w/_-]+(\s+(?!nodev)[\w,]+)*)'
    line='\1,nodev'

One of the lines from /etc/fstab that I am trying to add nodev is:

/dev/mapper/ex_sys-ex_home /home /ext4 rw,exec,auto,nouser,sync 1 2
like image 274
Brian Putt Avatar asked Sep 22 '14 15:09

Brian Putt


People also ask

What is Mount in ansible?

The ansible mount module lets you control and configure mount points on remote hosts. It provides basic functionalities such as mounting and unmounting of filesystems and devices. This article will learn how to use the Ansible mount module to manage mount points on remote systems.

How do you run a command in ansible?

The command module takes the command name followed by a list of space-delimited arguments. The given command will be executed on all selected nodes. The command(s) will not be processed through the shell, so variables like $HOSTNAME and operations like "*" , "<" , ">" , "|" , ";" and "&" will not work. Use the ansible.

How does fstab work?

Your Linux system's filesystem table, aka fstab , is a configuration table designed to ease the burden of mounting and unmounting file systems to a machine. It is a set of rules used to control how different filesystems are treated each time they are introduced to a system. Consider USB drives, for example.

How do you get ansible facts?

To access the variables from Ansible facts in the Ansible playbook, we need to use the actual name without using the ansible keyword. The gather_facts module from the Ansible playbook runs the setup module by default at the start of each playbook to gather the facts about remote hosts.


1 Answers

I wanted to state that there seems to be a new ansible module which covers all this much more easily: https://docs.ansible.com/ansible/latest/modules/mount_module.html

like image 91
TheFlipside Avatar answered Oct 05 '22 18:10

TheFlipside