Romain
Romain

Reputation: 181

Ansible command quotes

I would like to have the following command integrated in an Ansible playbook task:

cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'.

Any quote inside breaks the whole command. How I can avoid it to make it run the whole string?

Many thanks in advance.

Upvotes: 7

Views: 27229

Answers (2)

maxschlepzig
maxschlepzig

Reputation: 39047

You can simply use the YAML literal block string syntax. In that way you don't need to escape any quotes. Instead, you can pass your shell command as is.

Example:

- name: test task
  shell:
      cmd: |
          cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'
  tags: test

Upvotes: 15

imjoseangel
imjoseangel

Reputation: 3926

You can escape them with \”

example: "hello=\"hi\""

Upvotes: 7

Related Questions