So I simplified my playbook a bit. I disabled selinux on both servers and I'm still getting an error.
--- - name: Check for reboot hosts: baseserver-lx become: yes vars_files: - passwd.yml - vars.yml vars: script_dir: "~/" script: "~/needs-restarting.py" tasks: - name: Copy script copy: src: "{{ script }}" dest: "{{ script }}" owner: root group: root mode: 0700 - name: Check for reboot command: "{{ script }}" 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 ERROR: 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: [baseserver-lx]: FAILED! => {"changed": false, "msg": "Could not find or access '~/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"} On Mon, Oct 15, 2018 at 10:45 AM Kai Stian Olstad < ansible-project+l...@olstad.com> wrote: > On Thursday, 11 October 2018 22.30.13 CEST 'Chris Bidwell - NOAA Federal' > via Ansible Project wrote: > > 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 > > You don't need to do this, the file module will check if the directory > exist and create if it doesn't exist. > > > > > > - name: Does script exist? > > stat: > > path: "{{ script_dir }}/needs-restarting.py" > > register: fic > > You don't need to do this, the copy module will check if the file exist > and create/copy if it doesn't exist. > > > > - 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 > > If you are using Ansible 2.7 I recommend using the reboot module. > > https://docs.ansible.com/ansible/2.7/modules/reboot_module.html#reboot-module > > If not you should change it to this to avoid errors. > > - name: "Rebooting {{ ansible_hostname }}" > shell: sleep 2 && reboot > async: 1 > poll: 0 > 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 > > Instead of wait_for I highly recommend using wait_for_connection instead > because that module will check the remote host is ready to execute Ansible > modules before it continues. > (With the reboot module this is not needed) > > > > 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 > > The dot after the permission indicate that your file has a SELinux ACL, so > you should check your SELinux log to see if SELinux is blocking Ansible to > access the file. > > > -- > Kai Stian Olstad > > > -- > 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 ansible-project+unsubscr...@googlegroups.com. > To post to this group, send email to ansible-project@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/1921487.jDjfVBoyrm%40x1. > For more options, visit https://groups.google.com/d/optout. > -- Chris Bidwell, CISSP Space Weather Prediction Center National Oceanic Atmospheric Administration email: c <cbidw...@usgs.gov>hris.bidw...@noaa.gov office: 303-497-3204 mobile: 720-496-3126 -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAHKi8Ch5yQSD-M1J6z7AWAXmxz_m8fpkqs7AQxT5Q4kWLAy3Aw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.