Move files?

I am a complete newbie to Ansible and I’m piloting the tool at our company by writing a patching update playbook.

I am trying to move all *repo files in /etc/yum.repos.d to /etc/yum.repos.d/off so we can put our own custom repo file in place there. I know we can disable repos with the yum module, but we have a lot of custom repo files out in the directory on the servers, so I’d like to just move them all to ‘off’ and be done with it.

Is there a way to /bin/mv /etc/yum.repos.d/*repo /etc/yum.repos.d/off?

Also, if anyone has any tips/advice on pointing to a custom repo site and doing a yum update (and rebooting)… :slight_smile:

–Michael

Hi Michael,

To literally answer your question, you probably just want to do something like:

  • name: create directory
    file: path=/etc/yum.repos.d/off/ state=directory

  • name: move repo files out of the way
    command: mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/off/ creates=/etc/yum.repos.d/

The creates= argument will cause the task to be skipped if the path specified already exists.

But maybe instead of just moving the repos files out of the way, you could use yum-config-manager instead?

http://docs.fedoraproject.org/en-US/Fedora/16/html/System_Administrators_Guide/sec-Managing_Yum_Repositories.html

You could combine this with the creates= or removes= option to the command: call, too, if you can figure out which paths to reference.

-Tim

I tried mv with ‘command’ and it was squawking at /etc/yum.repos.d/*repo (error: could not stat file) like it wasn’t wildcarding the asterisk. Using ‘shell’ appears to work OK.

I learned if there is no file to move, it errors, but I can throw ignore_errors at it. I’m learning. :slight_smile:

I’ll look into yum-config-manager. The hard part is each system is unique and configured differently, so that’s why I decided to use the hammer and just move all/any yum repos out of the way and start fresh. :slight_smile:

MJ

Sorry, my bad–“command” doesn’t let you use shell wildcards and stuff, but “shell” does, as you found. :slight_smile:

-Tim

- shell: if [ -f /thepath/* ]; then <move_command>; fi

Thanks, Tim & James. I appreciate the help for this newbie.

-MJ