Hey all, me again!  So I've got this playbook that *should* run fine but it
dies at trying to copy.  Now I don't know if it's because it can't find it
locally having the problem copying it remotely.  Here it is:

cat check_for_reboot.yml
---
- name: Check for reboot
  hosts: testserver
  become: yes

  vars_files:
    - passwd.yml
    - vars.yml

  vars:
    script_dir: "/home/tsg/scripts"

  tasks:
    - name: Does script directory exist?
      stat:
        path: "{{ script_dir }}"
      register: dir_exists

    - name: Does script exist?
      stat:
        path: "{{ script_dir }}/needs-restarting.py"
      register: fic

    - name: Create scripts dir
      file:
        state: directory
        path: "{{ script_dir }}"
        owner: tsg
        group: tsg
        mode: 0755
      when: dir_exists.stat.exists == false

    - name: Copy script
      copy:
        src: "{{ script_dir }}/needs-restarting.py"
        dest: "{{ script_dir }}/needs-restarting.py"
        owner: tsg
        group: tsg
        mode: 0755
      when: fic.stat.exists == false

    - name: Check for reboot
      command: "{{ script_dir }}/needs-restarting.py -r"
      register: reboot_reqd
      ignore_errors: true
      changed_when: false

    - name: "Rebooting {{ ansible_hostname }}"
      shell: sleep 1 && reboot
      async: 30
      poll: 1
      ignore_errors: true
      when: reboot_reqd.rc == 1

    - name: Wait for ssh to come back available
      wait_for:
        host: "{{
(ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}"
        port: 22
        search_regex: OpenSSH
        delay: 10
        timeout: 240
      vars:
        ansible_connection: local
      when: reboot_reqd.rc == 1

Output:
TASK [Create scripts dir]
*************************************************************************************************************************************************
changed: [testserver]

TASK [Copy script]
********************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use
-vvv. The error was: If you are using a module and expect the file to exist
on the remote, see the remote_src option
fatal: [testserver]: FAILED! => {"changed": false, "msg": "Could not find
or access '/home/tsg/scripts/needs-restarting.py' on the Ansible
Controller.\nIf you are using a module and expect the file to exist on the
remote, see the remote_src option"}

Okay, so I know that file is on the src server (ansible server).

[tsg@server]$ pwd
/home/tsg/scripts
[tsg@server scripts]$ll
-rwxr-x---. 1 root tsg 8432 Aug 23 17:57 needs-restarting.py

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAHKi8CgQVVSu%3DgHFeH1oVg_t6jpsZ4W3dpfCUo-Eym-XEcHTJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
  • [ansible-project] Tryin... 'Chris Bidwell - NOAA Federal' via Ansible Project

Reply via email to