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, 2019 in Ansible by Purva
1,580 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, 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
4,246 views
0 votes
2 answers

Error while creating resource group on Azure using Ansible

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

answered Mar 17, 2020 in Ansible by Shrikant Yerge
1,583 views
+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 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,065 views
+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
4,514 views
+1 vote
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP