After creating a container I have a list of tasks I would like to run.
Is the recommended way simply to copy the script into the node fs or is there a better/correct way to do it?
Here is my shell version:
sudo cp initial-node-config.sh /var/lib/lxc/$N/rootfs/usr/local/sbin/
sudo lxc-attach -n $N -- /usr/local/sbin/initial-node-config.sh $I $N
Ansible version:
- name: Copy node init script
ansible.builtin.copy:
src: initial-node-config.sh
dest: "/var/lib/lxc/{{ item.hostname }}/rootfs/usr/local/sbin/initial-node-config.sh"
owner: root
group: root
mode: '0700'
with_items: "{{ nodes }}"
notify: Execute node init script
handlers:
- name: Execute node init script
community.general.lxc_container:
name: "{{ item.hostname }}"
container_command: "/usr/local/sbin/initial-node-config.sh {{ item.ip }} {{ item.hostname }}"
with_items: "{{ nodes }}"