I have got the following playbook:
`
I have got the following playbook:
`
Add delegate_to: localhost on the task(s) you need to run on localhost and not the remote host.
Thanks a lot Kai for the quick help. I will try this.
I have one more query though. What is the exact different between local_action and delegate_to ?
Nothing.
I prefer using delegate_to since it's then easy to add or remove the delegation.
If using local_action more change need to be done to add or remove it.
I tried the following modified playbook:
- hosts: Windows
gather_facts: false
tasks:
- name: Ensure Service status is running and startup mode set to Automatic
win_service:
name: MSSQLSERVER
state: started
start_mode: auto
- name: Send Job completion notification to MS Teams
script: /tmp/ansible_scripts/MSTeamsNotifications.pyc
args:
executable: /usr/bin/python
delegate_to: 127.0.0.1
…
but getting the following error:
TASK [Send Job completion notification to MS Teams] ****************************
19:57:29
9
fatal: [WinTest4143 → 127.0.0.1]: FAILED! => {“changed”: false, “msg”: “Could not find or access ‘/tmp/ansible_scripts/MSTeamsNotifications.pyc’ on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option”}
this file exists on Ansible Server and works fine. The file has full permissions too but it doesn’t work.
$ ls -lrt /tmp/ansible_scripts/MSTeamsNotifications.pyc
-rwxrwxrwx. 1 anks users 1043 Dec 15 07:21 /tmp/ansible_scripts/MSTeamsNotifications.pyc
$ /usr/bin/python /tmp/ansible_scripts/MSTeamsNotifications.pyc
MSTeamsNotifications.py - Send Notifications to MS Teams Team
1
Thanks and Regards,
Recommend using localhost and not 127.0.0.1, localhost is special in Ansible and does the right ting.
The script module copies the file to the remote host and execute the script, so in this case you should use the command module instead and just run the script/program since it's already on the Ansible controller.
Hello Kai,
Unfortunately, I am still getting the error. The current Playbook:
- hosts: Windows
gather_facts: false
tasks:
- name: Ensure Service status is running and startup mode set to Automatic
win_service:
name: MSSQLSERVER
state: started
start_mode: auto
- name: Send Job completion notification to MS Teams
command: ‘/usr/bin/python /tmp/ansiblescripts/MSTeamsNotifications.pyc’
delegate_to: localhost
Result:
TASK [Send Job completion notification to MS Teams] ****************************
task path: /var/lib/awx/projects/_6__innersource_cio_config_mgmt/playbooks/mssql/SQLE_Service_Status.yml:15
ESTABLISH LOCAL CONNECTION FOR USER: awx
EXEC /bin/sh -c ‘echo ~awx && sleep 0’
EXEC /bin/sh -c ‘( umask 77 && mkdir -p “echo /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436
” && echo ansible-tmp-1544892619.83-135217386386436=“echo /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436
” ) && sleep 0’
Using module file /var/lib/awx/venv/custom-venv/lib/python2.7/site-packages/ansible/modules/commands/command.py
PUT /var/lib/awx/.ansible/tmp/ansible-local-3LdqDbo/tmpLJ0CAV TO /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436/AnsiballZ_command.py
EXEC /bin/sh -c ‘chmod u+x /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436/ /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436/AnsiballZ_command.py && sleep 0’
EXEC /bin/sh -c ‘/var/lib/awx/venv/custom-venv/bin/python /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436/AnsiballZ_command.py && sleep 0’
EXEC /bin/sh -c ‘rm -f -r /var/lib/awx/.ansible/tmp/ansible-tmp-1544892619.83-135217386386436/ > /dev/null 2>&1 && sleep 0’
fatal: [WinTest4143-> localhost]: FAILED! => {
“changed”: true,
“cmd”: [
“/usr/bin/python”,
“/tmp/ansiblescripts/MSTeamsNotifications.pyc”
],
“delta”: “0:00:00.022198”,
“end”: “2018-12-15 16:50:20.371504”,
“invocation”: {
“module_args”: {
“_raw_params”: “/usr/bin/python /tmp/ansiblescripts/MSTeamsNotifications.pyc”,
“_uses_shell”: false,
“argv”: null,
“chdir”: null,
“creates”: null,
“executable”: null,
“removes”: null,
“stdin”: null,
“warn”: true
}
},
“msg”: “non-zero return code”,
“rc”: 2,
“start”: “2018-12-15 16:50:20.349306”,
“stderr”: “/usr/bin/python: can’t open file ‘/tmp/ansiblescripts/MSTeamsNotifications.pyc’: [Errno 2] No such file or directory”,
“stderr_lines”: [
“/usr/bin/python: can’t open file ‘/tmp/ansiblescripts/MSTeamsNotifications.pyc’: [Errno 2] No such file or directory”
],
“stdout”: “”,
“stdout_lines”:
}
Another thing i noticed is, when i try to sudo to awx user, i get a expired password error. What is the default password for awx user. I don’t remember setting it up anywhere during installation of Tower.
# sudo su - awx
sudo: Account or password is expired, reset your password and try again
Changing password for root.
(current) UNIX password:
If you are seeing this issue in AWX you are probably coming across bubble wrap https://docs.ansible.com/ansible-tower/3.1.4/html/administration/proot_func_variables.html. Bubblewrap limits what directories a playbook can run and IIRC it’s default is the project directory of the playbook itself. I recommend keeping that script as part of the playbook got repo in the files directory and referencing it by name.