0

I need to rename hosts_example or hosts_Example to be named as hosts_real if any of the file exists

- name: Playbook to Standardize  Hosts
  hosts: test
  vars:
    destpath: /etc/hosts_real
    filename: [ /etc/hosts_example,/etc/hosts_Example ]

  tasks:
    - name: Check if file exists
      stat:
        path: "{{ item }}"
      with_items:
        - "{{ filename }}"
      register: check_file_name

    - debug:
        msg: "{{check_file_name}}"

    - name: Rename file
      command: mv "{{ item }}"{{destpath}}"
      with_items:
        - "{{ check_file_name.results }}"
      when: item.stat.exists == true

I tried this am getting errors and not able to achieve the desired result

celcoprab
  • 35
  • 1
  • 7

1 Answers1

0

name: replace file

shell: mv /local/oracle/12.2/oldora.ora /local/oracle/12.2/tnsnames.ora

become: appuser

Works for us. Update your path in the shell command. I dont think the file module has a rename command. If you have a variable in your shell line put the whole line in quotes like:

shell: "mv {{ path_1 }} {{ path_2 }}"