Could you describe your problem and show us the output and indicate what you expect ? If I don't know what you are doing, I cannot test to reproduce it.
Something like:
Could you describe your problem and show us the output and indicate what you expect ? If I don't know what you are doing, I cannot test to reproduce it.
Something like:
Merry Christmas guys!
Few issues:
1. return from/to ansible using "script" module was not in what I expect from JSON output
-- This had been solved after I resync the ansible from git. it was the updated "raw" module, I believe.
2. There are no outcome in stderr
-- this had been explained by Dag, is cause by the "raw" module calling ssh with Tty and and be "silence". Thanks for the trick!
3. stdout from "script" module is all in 1 line but with escape characters. Will paste the sample output after the holidays!
Overall, "script" module is what I expect.
next I need to learn how to convert my bash scripts into ansible module.
Hi guys,
When I run “raw” module to get “vmstat 1 5”:
192.168.2.18 | success | rc=0 >>
procs -----------memory---------- —swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 25232 2900 1616 13840 21 41 216 76 976 86 1 17 78 4 0
0 0 25232 2900 1616 13840 0 0 0 0 969 46 0 16 84 0 0
0 0 25232 2900 1616 13840 0 0 0 0 950 30 0 16 84 0 0
0 0 25232 2900 1616 13840 0 0 0 0 978 29 0 14 86 0 0
0 0 25232 2900 1616 13840 0 0 0 0 955 29 0 14 86 0 0
But when I put the command into a script, and use “script” module to call it:
192.168.2.18 | success >> {
“rc”: 0,
“stderr”: “”,
“stdout”: “procs -----------memory---------- —swap-- -----io---- --system-- -----cpu------\r\n r b swpd free buff cache si so bi bo in cs us sy id wa st\r\n 1 1 25232 2000 1636 13508 19 37 196 70 975 83 1 17 78 4 0\r\n 0 0 25232 2632 1592 13040 0 0 0 0 969 46 0 16 59 25 0\r\n 0 0 25232 2632 1592 13036 0 0 0 0 952 30 0 15 85 0 0\r\n 0 0 25232 2632 1592 13036 0 0 0 0 969 56 0 16 84 0 0\r\n 0 0 25232 2632 1592 13036 0 0 0 0 963 27 0 14 86 0 0\r\n”
}
This is the sample script I wrote:
#!/bin/bash
vmstat 1 5
exit 0
It seem like stdout, is having “\r\n” escape value.
Thanks.
Hello,
Following this old message, I would need to use creates= on the script module.
Would you still accept a patch adding creates= and removes= to the script module ?
I plan on copy/pasting the code out of the command module ; would this be the correct way to go ?
Thank you
Jerome
I would!
Looking at the command module probably won’t help though, as the script module is implemented entirely as an action plugin.
You will probably have to call the ‘stat’ module via the API inside the ‘script’ action plugin, and get back the results as to whether the files are absent or not.
Short term workaround is of course use “stat”, “register” the result in that task, and then use “when” on the script module as a conditonal.
Jerome,
Would you still accept a patch adding creates= and removes= to the script
module ?
+1 !!!
-JP
Hello Michael,
regarding script.creates= and script.removes=
could you have a look to this commit on my fork :
https://github.com/jeromew/ansible/commit/764d8bb37e155039dc6c36bea638983c93de1b61
and tell me if that’s not too far from what you had in mind ?
Thank you
Jerome
The “file exists” stuff should be handled by “execute module” rather than calling low level shell ops and defining “remote path exists”, just call the stat module.
See how the template module does it here: https://github.com/ansible/ansible/blob/devel/lib/ansible/runner/action_plugins/template.py
self.runner._execute_module(conn, tmp, 'file', module_args, inject=inject, complex_args=complex_args)
minor typo here “since %s does not exists”, probably want “does not exist”.
BTW, this is probably better asked on ansible-devel, which is our list for discussing development topics.
Thanks!