I am using below playbook for mounting partitions on another EBS volumes while provisioning instance on AWS
---
- name: Mounting necessary partitions
hosts: localhost
become: yes
become_user: root
tasks:
- name: Ansible formating partitions.
command: "{{ item }}"
loop:
- mkswap -f {{ ebs_swap }}
- mkfs.xfs -f {{ ebs_home }}
- mkfs.xfs -f {{ ebs_var }}
- mkfs.xfs -f {{ ebs_tmp }}
- mkfs.xfs -f {{ ebs_app }}
- mv -f /home /home_old
- mv -f /var /var_old
- name: Dispaly uuid & store in variable
command: blkid -s UUID -o value {{ ebs_swap }}
register: uuid_swap
- name: Dispaly uuid & store in variable
command: blkid -s UUID -o value {{ ebs_home }}
register: uuid_home
- name: Dispaly uuid & store in variable
command: blkid -s UUID -o value {{ ebs_var}}
register: uuid_var
- name: Dispaly uuid & store in variable
command: blkid -s UUID -o value {{ ebs_tmp }}
register: uuid_tmp
- name: Dispaly uuid & store in variable
command: blkid -s UUID -o value {{ ebs_app }}
register: uuid_app
- name: Creates directory
file:
path: "{{ item }}"
state: directory
with_items:
- /home
- /var
- /tmp
- /app
- name: Add the below lines
blockinfile:
path: /etc/fstab
state: present
block: |
UUID={{ uuid_swap.stdout }} swap swap defaults 0 0
UUID={{ uuid_home.stdout }} /home xfs defaults,nodev 0 0
UUID={{ uuid_var.stdout }} /var xfs defaults,noexec,nosuid,nodev 0 0
UUID={{ uuid_tmp.stdout }} /tmp xfs defaults,noexec,nosuid,nodev 0 0
UUID={{ uuid_app.stdout }} /app xfs defaults 0 0
- name: Mounting disks permanently
command: "{{ item }}"
loop:
- swapon -a
- mount -a
- name: Copy multiple Directories
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
with_items:
- { src: '/home_old/',dest: '/home/',mode: preserve}
- { src: '/var_old/',dest: '/var/',mode: preserve}
I have tried multiple ways to copy the data back to newly mounted EBS volumes at task name
Copying /home data on new EBS
.
I have tried using copy
synchronization
& rsync
modules. I know using cp is not recommended option but i can not see any other option related to syncing the data between to directories with preserving permissions.
But when i do it manually it works perfect.
I am mounting these partitions on another EBS is just coz of CIS hardening steps includes it.
I have followed couple of blogs already. such as
- one 2. two
Can anyone help in solving this. this is very urgent.
ERROR: failed: [localhost] (item={u'dest': u'/var/', u'src': u'/var_old/'}) => {"ansible_loop_var": "item", "changed": false, "item": {"dest": "/var/", "src": "/var_old/"}, "msg": "could not find src=/run/acpid.socket, Could not find or access '/run/acpid.socket' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}