I'm trying to use the Ansible replace module to change some text in a file on a Windows Server 2019 Standard target. I'm using Ansible 2.8.3 running on Python 2.7
- name: REPLACE | Replace baseline.local with FQDN in InternetSettings.xml
replace:
path: '/path/to/settings.xml'
regexp: 'baseline\.local'
replace: '{{ FQDN }}'
I don't think the issue is the path, although one of the directories on the path to the file has brackets '{}' in its name. Could that be it?
I've tried to do the same thing with win_lineinfile, and it didn't throw an error with the same path, but it'd be difficult in this case to replicate the functionality of replace, which is really what I need.
EDIT 2: It works when I copy the file over to my local machine and delegate to 127.0.0.1. I'm running ansible from a Windows Subsystem for Linux (WSL) installation. It also works when I copy the file to a remote linux system and run replace there, so it seems to be a Windows problem.?
EDIT: The stack trace of the error I'm getting:
"Exception calling "Create" with "1" argument(s): "At line:4 char:21
+ def _ansiballz_main():
+ ~
An expression was expected after '('.
At line:13 char:27
+ except (AttributeError, OSError):
+ ~
Missing argument in parameter list.
At line:15 char:7
+ if scriptdir is not None:
+ ~
Missing '(' after 'if' in if statement.
At line:22 char:7
+ if sys.version_info < (3,):
+ ~
Missing '(' after 'if' in if statement.
At line:22 char:30
+ if sys.version_info < (3,):
+ ~
Missing expression after ','.
At line:22 char:25
+ if sys.version_info < (3,):
+ ~
The '<' operator is reserved for future use.
At line:24 char:32
+
My teammates and I suspect that this issue is the result of attempting to use an ansible module not built for windows on a windows target - more particularly, a target that doesn't have python installed. We suspect that some part of the compiling of python on the ansible controller or subsequent execution of the python binary on the windows target is what's really causing the problem here. We've decided on the workaround of just using win_shell with powershell's 'replace' to do what we need to do.
Try changing your regexp string to double quotes:
regexp: "baseline.local"
I'm encountering problems saving a document as I can see in the debug area:
NSFileVersion tried to tried to add a new generation and failed. Versioned file URL: file:///Users/mike97/Downloads/test%20copy.xml, contents URL: file:///Users/mike97/Downloads/test%20copy~.xml, error: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.069020+0200 XML Parser[2095:54823] NSDocument failed to preserve the old version of a document. Here's the error:
Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}}
2017-06-19 20:19:53.118611+0200 XML Parser[2095:54823] <XML_Parser.Document: 0x6000001014d0>: An error occurred while attempting to preserve the backup file at file:///Users/mike97/Downloads/test%20copy~.xml: Error Domain=GSLibraryErrorDomain Code=2 "Unable to open /Users/mike97/Downloads/test copy~.xml" UserInfo={NSDescription=Unable to open /Users/mike97/Downloads/test copy~.xml, NSUnderlyingError=0x608000856020 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory" UserInfo={NSDescription=No such file or directory}}} ##
The app try to atomically save a file called 'test copy.xml' and doing this just rename that file to 'test copy~.xml', why cannot found the original one. In fact changing the option parameter saving the data the error gone.
This is the code I'm using in my NSDocument subclass:
override func writeSafely(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType) throws {
if let vc = self.windowController?.contentViewController as? ViewController {
switch typeName {
case "XML v1":
do {
try vc.parser?.save().write(to: url, options: [])
} catch {
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
break
..
In NSData.WritingOptions we can found some of the options to save a file, but I'm not sure what of them I need. Anyone care to explain me what they are and what are the best using the 'writeSafely' method chosen by me?
Also that method handles possible errors, so that a non-atomic write operation appear to be enough, but I wonder on how can I preserve the 'versioning' functionality by macOS.
This could be a possbile duplicate. Still im not able to find a solution for it.Yes i tried with regexp but is there any other way to solve it?
String s="This is a â¦sample ⦠Java class to show the issueâ¨\nHow to solve it?";
try {
System.out.print("ANSWER="+URLDecoder.decode(s, "UTF-8")); ;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
How can i fix this issue? Can some one help
Thanks in advance
The console output
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:136), pid=17620, tid=14220
# fatal error: Invalid layout of preloaded class
#
# JRE version: (7.0_79-b15) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
Try this
String yourString= "This is a â¦sample ⦠Java class to show the issueâ¨\nHow to solve it?";
Pattern myPattern = Pattern.compile("[^a-zA-Z0-9]");
Matcher myMatcher = myPattern.matcher(yourString);
while(myMatcher.find())
{
String temp= myMatcher.group();
yourString=yourString.replaceAll("\\"+temp, " ");
}
System.out.println(yourString);
I am actually using wamp 2.5 with PHP 5.5.12 and when I try to create a phar file it returns me the following message :
Uncaught exception 'UnexpectedValueException' with message 'creating archive "..." disabled by the php.ini setting phar.readonly'
even if I turn to off the phar.readonly option in php.ini.
So how can I enable the creation of phar files ?
I had this same problem and pieced together from info on this thread, here's what I did in over-simplified explanation:
in my PHP code that's generating this error, I added echo phpinfo(); (which displays a large table with all sort of PHP info) and in the first few rows verify the path of the php.ini file to make sure you're editing the correct php.ini.
locate on the phpinfo() table where it says phar.readonly and note that it is On.
open the php.ini file from step 1 and search for phar.readonly. Mine is on line 995 and reads ;phar.readonly = On
Change this line to phar.readonly = Off. Be sure that there is no semi-colon at the beginning of the line.
Restart your server
Confirm that you're phar project is now working as expected, and/or search on the phpinfo()table again to see that the phar.readonly setting has changed.
phar.readonly can only be disabled in php.ini due to security reasons.
If you want to check that it's is really not done using other method than php.ini then in terminal type this:-
$ php -r "ini_set('phar.readonly',0);print(ini_get('phar.readonly'));"
If it will give you 1 means phar.readonly is On.
More on phar.configuration
Need to disable in php.ini file
Type which php
Gives a different output depending on machine e.g.
/c/Apps/php/php-7.2.11/php
Then open the path given not the php file.
E.g. /c/Apps/php/php-7.2.11
Edit the php.ini file
could do
vi C:\Apps\php\php-7.2.11\php.ini
code C:\Apps\php\php-7.2.11\php.ini
[Phar]
; http://php.net/phar.readonly
phar.readonly = Off
; http://php.net/phar.require-hash
phar.require_hash = Off
Save
Using php-cli and a hashbang, we can set it on the fly without messing with the ini file.
testphar.php
#!/usr/bin/php -d phar.readonly=0
<?php
print(ini_get('phar.readonly')); // Must return 0
// make sure it doesn't exist
#unlink('brandnewphar.phar');
try {
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
} catch (Exception $e) {
echo 'Could not create phar:', $e;
}
echo 'The new phar has ' . $p->count() . " entries\n";
$p->startBuffering();
$p['file.txt'] = 'hi';
$p['file2.txt'] = 'there';
$p['file2.txt']->compress(Phar::GZ);
$p['file3.txt'] = 'babyface';
$p['file3.txt']->setMetadata(42);
$p->setStub('<?php
function __autoload($class)
{
include "phar://myphar.phar/" . str_replace("_", "/", $class) . ".php";
}
Phar::mapPhar("myphar.phar");
include "phar://myphar.phar/startup.php";
__HALT_COMPILER();');
$p->stopBuffering();
// Test
$m = file_get_contents("phar://brandnewphar.phar/file2.txt");
$m = explode("\n",$m);
var_dump($m);
/* Output:
* there
**/
✓ Must be set executable:
chmod +x testphar.php
✓ Must be called like this:
./testphar.php
// OUTPUT there
⚠️ Must not be called like this:
php testphar.php
// Exception, phar is read only...
⚠️ Won't work called from a CGI web server
php -S localhost:8785 testphar.php
// Exception, phar is read only...
For anyone who has changed the php.ini file, but just doesn't see any changes. Try to use the CLI version of the file. For me, it was in /etc/php/7.4/cli/php.ini
Quick Solution!
Check:
cat /etc/php/7.4/apache2/php.ini | grep phar.readonly
Fix:
sed -i 's/;phar.readonly = On/;phar.readonly = Off/g' /etc/php/7.4/apache2/php.ini
I want to ask opencart problem, I got this error:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
OK
{"country_id":"100","name":"Indonesia","iso_code_2":"ID","iso_code_3":"IDN" ,"address_format":"","postcode_required":"1","zone":[{"zone_id":"1507","country_id":"100","name":"Aceh","code":"Aceh","status":" 1"},{"zone_id":"1508","country_id":"100","name":"Bali","code":"Bali","statu s":"1"},{"zone_id":"1509","country_id":"100","name":"Banten","code":"Banten ","status":"1"},{"zone_id":"1510","country_id":"100","name":"Bengkulu","cod e":"BE","status":"1"},{"zone_id":"1511","country_id":"100","name":"D.I.Yogy akarta","code":"YG","status":"1"},{"zone_id":"1512","country_id":"100","nam e":"Gorontalo","code":"GO","status":"1"},{"zone_id":"1513","country_id":"10 0","name":"Jakarta","code":"Jakarta","status":"1"},{"zone_id":"1514","count ry_id":"100","name":"Jambi","code":"JA","status":"1"},{"zone_id":"1515","co untry_id":"100","name":"Jawa Barat","code":"JB","status":"1"},{"zone_id":"1516","country_id":"100","name ":"Jawa Tengah","code":"JT","status":"1"},{"zone_id":"1517","country_id":"100","nam e":"Jawa Timur","code":"JI","status":"1"},{"zone_id":"1518","country_id":"100","name ":"Kalimantan Barat","code":"KB","status":"1"},{"zone_id":"1519","country_id":"100","name ":"Kalimantan Selatan","code":"KS","status":"1"},{"zone_id":"1520","country_id":"100","na me":"Kalimantan Tengah","code":"KT","status":"1"},{"zone_id":"1521","country_id":"100","nam e":"Kalimantan Timur","code":"KI","status":"1"},{"zone_id":"1522","country_id":"100","name ":"Kepulauan Bangka Belitung","code":"BB","status":"1"},{"zone_id":"1537","country_id":"100","n ame":"Kepulauan Riau","code":"KPR","status":"1"},{"zone_id":"1523","country_id":"100","name ":"Lampung","code":"LA","status":"1"},{"zone_id":"1524","country_id":"100", "name":"Maluku","code":"MA","status":"1"},{"zone_id":"1525","country_id":"1 00","name":"Maluku Utara","code":"MU","status":"1"},{"zone_id":"1526","country_id":"100","name ":"Nusa Tenggara Barat","code":"NB","status":"1"},{"zone_id":"1527","country_id":"100","name ":"Nusa Tenggara Timur","code":"NT","status":"1"},{"zone_id":"1528","country_id":"100","name ":"Papua","code":"PA","status":"1"},{"zone_id":"3970","country_id":"100","n ame":"Papua Barat","code":"PB","status":"1"},{"zone_id":"1529","country_id":"100","name ":"Riau","code":"RI","status":"1"},{"zone_id":"3971","country_id":"100","na me":"Sulawesi Barat","code":"SR","status":"1"},{"zone_id":"1530","country_id":"100","name ":"Sulawesi Selatan","code":"SN","status":"1"},{"zone_id":"1531","country_id":"100","na me":"Sulawesi Tengah","code":"ST","status":"1"},{"zone_id":"1532","country_id":"100","nam e":"Sulawesi Tenggara","code":"SG","status":"1"},{"zone_id":"1533","country_id":"100","n ame":"Sulawesi Utara","code":"SA","status":"1"},{"zone_id":"1534","country_id":"100","name ":"Sumatera Barat","code":"SB","status":"1"},{"zone_id":"1535","country_id":"100","name ":"Sumatera Selatan","code":"SS","status":"1"},{"zone_id":"1536","country_id":"100","na me":"Sumatera Utara","code":"SU","status":"1"}],"status":"1"}<b>Warning</b>:
file_put_contents(C:\xampp\htdocs\rumahjoy\vqmod/logs/Fri.log) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: No such file or directory in <b>/home/sloki/user/h1604/sites/rumahjoy.com/www/vqmod/vqmod.php</b> on line <b>395</b>LOG FILE COULD NOT BE WRITTEN
I have 2 question:
First, what happen with my vqmod? It got C:\xampp (localhost). I've hosted it to server which must be /home/sloki/user/.......
Second, what's wrong with JSON error? Because at localhost it works fine.
Upgrade to VQmod 2.3.2 then its solved..