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! => 
{  
   "changed":true,
   "cmd":"if [ -f ~/.zshrc ]; then cp ~/.zshrc{,.orig}; fi",
   "delta":"0:00:00.002640",
   "end":"2017-04-11 12:32:35.886640",
   "failed":true,
   "rc":1,
   "start":"2017-04-11 12:32:35.884000",
   "stderr":"cp: missing destination file operand after '/root/.zshrc{,.orig}'\nTry 'cp --help' for more information.",
   "stderr_lines":[  
      "cp: missing destination file operand after '/root/.zshrc{,.orig}'",
      "Try 'cp --help' for more information."
   ],
   "stdout":"",
   "stdout_lines":[  

   ]
}
Mar 14 in Ansible by Purva
68 views

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 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,810 points
740 views
0 votes
1 answer

Error while creating resource group on Azure using Ansible

Hey, @Kiara seems like you're using an ...READ MORE

answered Mar 26 in Ansible by Olly
72 views
+13 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,380 points
213 views
0 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 in Ansible by Kim
473 views
0 votes
3 answers