escaping in a shell module

30 views
Skip to first unread message

danish09

unread,
Mar 6, 2021, 7:18:16 AM3/6/21
to Ansible Project
Hi,

ansible 2.4.0
remote environment: ubuntu 14.04
host/controller: Ubuntu 16.04.7 LTS

I have a task to extract some usernames from the passwd file

- name: extract usernames from password file 
  shell: "awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) && ($6="/sftp")' /etc/passwd > /home/xxxxxxxx/migrate/passwd.mig"

However, I am not sure why ansible is complaining when I run the above command.

When I run the awk command on the server CLI it runs fine. I have even tried escaping "/sftp" with a \\ but then awk complains so not sure how to g about it.

Thanks 

Danish

danish09

unread,
Mar 7, 2021, 2:22:13 AM3/7/21
to Ansible Project
Thanks everyone, got this working.

awk -v LIMIT=$UGIDLIMIT -F':' '($3>=LIMIT) && ($3!=65534) && ($6=="/sftp")' /etc/passwd > /home/ xxxxxxxx /migrate/passwd.mig

Reply all
Reply to author
Forward
0 new messages