nodes_wait 60 || true # ans CMD: run CMD as greg in his project directory. ans() { timeout 300 runuser -l greg -c "cd ~/ansible && $*" "$OUT"; grep -Eq "^node1 +: ok=" "$OUT" && grep -Eq "^node2 +: ok=" "$OUT" && ! grep -E " : ok=" "$OUT" | grep -Eq "(changed|unreachable|failed)=[1-9]"' need "the second run didn't restart sshd" '[ -n "$B1" ] && [ "$(sshd_start node1)" = "$B1" ] && [ "$(sshd_start node2)" = "$B2" ]' task 2 "One marked three-line block in /etc/motd, with the changed line" for n in $(nodes_names); do need "/etc/motd on $n has one BEGIN and one END marker" "[ \"\$(in_node $n grep -c BEGIN /etc/motd)\" = 1 ] && [ \"\$(in_node $n grep -c END /etc/motd)\" = 1 ]" need "the block on $n has the three lines, with Questions: admin@lab.example" "[ \"\$(in_node $n cat /etc/motd | sed -n '/BEGIN/,/END/p' | sed '1d;\$d')\" = \"\$BLOCK\" ]" need "/etc/motd on $n still starts with its own line" "in_node $n head -1 /etc/motd | grep -qx '$n, a practice node'" done task 3 "/etc archived as /root/etc.tar.bz2 on every node, fetched to backups/" for n in $(nodes_names); do need "/root/etc.tar.bz2 on $n is a bzip2 tar file of /etc" "in_node $n python3 -c '$TARPY' /root/etc.tar.bz2" need "/home/greg/ansible/backups/$n/root/etc.tar.bz2 is a copy of it" "python3 -c '$TARPY' /home/greg/ansible/backups/$n/root/etc.tar.bz2" done rm -f "$OUT"