# The control node: ansible-core and greg's project, with an inventory but # not the ansible.posix collection (task 1). pkg_installed ansible-core || { echo ansible-core >>"$LAB_STATE/missing"; pkg_install ansible-core; } user_add greg install -d -m 700 -o greg -g greg /home/greg/.ssh runuser -u greg -- ssh-keygen -q -t ed25519 -N '' -f /home/greg/.ssh/id_ed25519 install -d -m 755 -o greg -g greg /home/greg/ansible cat >/home/greg/ansible/ansible.cfg <<'EOF' [defaults] inventory = inventory remote_user = ansible host_key_checking = false EOF printf '[nodes] node1 ' >/home/greg/ansible/inventory chown greg: /home/greg/ansible/ansible.cfg /home/greg/ansible/inventory # Task 1 installs ansible.posix; note whether there was a system-wide copy, # so reset can take away one the student adds there. [ -d /usr/share/ansible/collections/ansible_collections/ansible/posix ] || echo /usr/share/ansible/collections/ansible_collections/ansible/posix >>"$LAB_STATE/new-dirs" # The managed node; its sshd_config leaves PermitRootLogin commented out (task 2). nodes_up 1 # greg's key goes to ansible on every node, and ansible may use sudo without # a password. for n in $(nodes_names); do in_node -i "$n" 'install -d -m 700 -o ansible -g ansible /home/ansible/.ssh && install -m 600 -o ansible -g ansible /dev/stdin /home/ansible/.ssh/authorized_keys && echo "ansible ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/ansible && chmod 440 /etc/sudoers.d/ansible'