Error while copying files using ansible role

0 votes

I'm trying to copy files using an ansible role. 

- name: Backing up existing ~/.zshrc
  shell: if [ -f ~/.zshrc ]; then cp ~/.zshrc{,.orig}; fi
  become: true
  become_user: root
  when: installation|success

However, I end up with this error:

fatal: [localhost]: FAILED! => 
   "cmd":"if [ -f ~/.zshrc ]; then cp ~/.zshrc{,.orig}; fi",
   "end":"2017-04-11 12:32:35.886640",
   "start":"2017-04-11 12:32:35.884000",
   "stderr":"cp: missing destination file operand after '/root/.zshrc{,.orig}'\nTry 'cp --help' for more information.",
      "cp: missing destination file operand after '/root/.zshrc{,.orig}'",
      "Try 'cp --help' for more information."

Mar 14, 2019 in Ansible by Purva

1 answer to this question.

0 votes

Add the following as an argument to the shell module to run the commands in Bash:

executable: /bin/bash
answered Mar 14, 2019 by Yesha
Why does this happen though?

Not all shells support brace expansion and you can see in the error message cp: missing destination file operand after '/root/.zshrc{,.orig}', that it took the argument too literally.

Related Questions In Ansible

0 votes
1 answer

Using multiple config files using same template in a role in ansible

Go through this include_role module: tasks: - ...READ MORE

answered Jun 5, 2018 in Ansible by DareDev
• 6,890 points
0 votes
2 answers

Error while creating resource group on Azure using Ansible

Please check you indentation, remove all spaces ...READ MORE

answered Mar 16, 2020 in Ansible by Shrikant Yerge
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
0 votes
1 answer

Syntax error while using block in ansible role

block should be on the same indentation level ...READ MORE

answered Mar 13, 2019 in Ansible by Kim
+1 vote
3 answers