ansible autofs mount

Dear All.
I am working on a project where we have a scenario in which we have to mount an NFS file system when each time system boots up ( we spin up using AWS/GITLAB CI/CD approach) so each time when i run the pipleline i get new instance with new Private ip, but my NFS( EFS in aws) will remain same and the mount point also.

Environment is as below :

infrastructure is build in AWS via terraform
configuration management we are using Ansible.

Situation is like this below :

We have to deploy a software which is loaded in S3 bucket , when the gitlab runner build the AMI we mount the NFS file system using normal way of mouting using the ansible and download the binaries in the file system . Once its extracted file system will umount and AWS ami creation will start.

In the deployment phase i have to mount the file system so that RDS can access will start provisioning the application environment , i think the best option is autofs instead of confd ( any suggessions are welcome) but if i use ansible for autofs how i can go for configuration ? i just need to mount the file system during the system boot itself thats it .

Thanks
CK

Dear All.
Any suggestions ?

Thanks

Is this at first boot only, or at every boot?

Assuming your AMI as the plumbing to mount NFS, mount it in the userdata script, do your load, then unmount it.

Our userdata variable in Ansible for new instances looks like this (non-EFS stuff removed):

user_data: |
#cloud-config
runcmd:

  • file_system_id=“{{ efs.efs.file_system_id }}”
  • efs_directory=“/mnt/efs”

[… other stuff …]

  • mkdir -p ${efs_directory}
  • echo “${file_system_id}:confused: ${efs_directory} efs defaults,_netdev 0 0” >> /etc/fstab
  • mount -a -t efs defaults
    [ … copy some stuff off EFS … ]
    [ … other stuff …]