以下のような ansible のレシピを書いたのですが ansible-playbook を実行すると SyntaxError になって失敗します
(シェルの中身は AWS inspector の推奨対応をコピーしたもので bash に貼り付けると実行できます)
shell: |
for user in `awk -F: '($3 < 1000) {print $1 }' /etc/passwd` ; do
if [ $user != ""root"" ]; then
usermod -L $user
if [ $user != ""sync"" ] && [ $user != ""shutdown"" ] && [ $user != ""halt"" ]; then
usermod -s /sbin/nologin $user
fi
fi
done
https://docs.ansible.com/ansible/2.5/modules/shell_module.html
こちらに複数行のシェル書き方があったので真似してみたんですが
shell: |
はヒアドキュメントというわけではないんでしょうか
エラーメッセージは以下になります
FAILED! => {"reason": "Syntax Error while loading YAML.\n expected <block end>, but found '<scalar>'\n\nThe error appears to be in '/home/ec2-user/git/ansible/roles/inspector/tasks/user.yml': line 17, column 50, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n shell: |\n for user in `awk -F: '($3 < 1000) {print $1 }' /etc/passwd` ; do\n ^ here\nThis one looks easy to fix. It seems that there is a value started\nwith a quote, and the YAML parser is expecting to see the line ended\nwith the same kind of quote. For instance:\n\n when: \"ok\" in result.stdout\n\nCould be written as:\n\n when: '\"ok\" in result.stdout'\n\nOr equivalently:\n\n when: \"'ok' in result.stdout\"\n"}
|
パイプとは無関係です。