ANSIBLE - reading hosts and doing something with them - loops

I am new to ansible, to be honest cannot work anything out so trying something this tricky is proving fruitless. Hopefully someone is able to assist?
I will try and explain the totally of what I am trying to achieve to have the full picture.
I have a .net application where the config differs for each environment that it is deployed - which is typical. What I need to do is edit the config file post deployment of an msi. I think I have an understanding of how to run something after the msi.
the config file will be a mix of hosts, and values for each host, but the value will depend on the host type
[hosttype1]
server1
server2
[hosttype2]
server1
server3
server5
[hosttype3]
....
In a different file I will have something like
[hosttype1]
values1
values2
[hosttype2]
values3
values4
The code will need to read the hosttype from each file and then merge the two values into a variable that I can then use to inject into the config file
the hosttypes is dynamic per environment
The output will be something like
"server1" value=values1
"server1" value=values2
"server2" value=values1
"server2" value=values2
"server1" value=values3
"server1" value=values4
"server3" value=values3
"server3" value=values4
"server5" value=values3
"server5" value=values4
Hope that makes sense
As it stands I have absolutely no idea how to loop over the first list, let alone loop over both and join the results together to generate something that can be used.
What I am trying to do is find a way to loop over both these files and effectively merge based of there types. The result of this would be used in the application config.
This may be completely the wrong approach so if there are other approaches then I'd happily to and work through these approaches, just need some thoughts, ideas, suggestions really as to how I should proceed.

Related

"?" character in MSSQL DB getting replaced with (capital A with grave accennt) when displayed by ASP script

I'm attempting to provide support for a legacy ASP/MSSQL web application - I wasn't involved in the development of the software (the company that built it no longer exists) & I'm not the admin of the server where it's hosted, I just manage the hosting for the owners of the site via a reseller account. I'm also not an ASP developer (more a PHP guy), and am not that familiar with it beyond the basics - updating DB connection strings after server migrations, etc.
The issue is that the site in question stores the content of individuals pages in an MSSQL database, and much of the content includes links. Almost all of the internal links on the site are format like "main.asp?123" (with "123" being the ID of a database row). The problem is, starting sometime in the last 8 months or so*, something caused the links in the DB content to show up as "main.aspÀ123" instead - in other words, the "?" character is being replaced by the "À" character (capital A with grave accent). Which, of course, breaks all of those links. Note that Stackoverflow won't allow me to include that character in the post title, because it seems to think that it indicates I'm posting in Spanish...?
(*unfortunately I don't know the timing beyond that, the site owners didn't know when the issue started occurring, so all I have to go by is an archive.org snapshot from last October, where it was working)
I attempted to manually change the "?" character in one of the relevant DB records to "?" (the HTML entity for the question mark), but that didn't make any difference. I also checked the character encoding of the HTML code used to display the content, but that doesn't seem to be the cause either - the same ASP files contain hard-coded links to some of the same pages (formatted exactly the same way), and those work correctly: the "?" doesn't get replaced.
I've also connected to the database directly with the MSSQL Management Studio Express application, but couldn't find any charset/character encoding options for either the database or the table.
And I've tried contacting the hosting provider, but they (M247 UK, in case anyone is curious) have been laughably unhelpful. The responses from them have been along the lines of "durrrrrr, we checked a totally different link that wasn't actually the one that you clearly described AND highlighted in a screenshot, and it works when we check the wrong link, so the problem must be resolved, right?" Suffice it to say, I wouldn't recommend them - used to be a customer of RedFox hosting, and the quality of customer has dropped off substantially since M247 bought them.
Any suggestions? If this were PHP/MySQL, I'd probably start by creating a small test script that did nothing but fetch one of the relevant records and display it's contents, to narrow down the issue - but I'm not familiar enough with ASP to do that here, at least not without a fair amount of googl'ing (and most of the info I can find is specific to ASP.net instead).
Edit: the thread suggested as a solution appears to be for character encoding issues when writing to MSSQL, not reading from it - and I've tried the solutions suggested in that thread, none make any difference.
Looks like you're converting from UNICODE to ASCII somewhere along the line...
Have a look at this to get a quick demo of what happens. In particular, pay attention to the ascii derived from inr, versus the ascii derived from unicode...
SELECT
t.n,
ascii_char = CHAR(t.n),
unicode_char = NCHAR(t.n),
unicode_to_ascii = CONVERT(varchar(10), NCHAR(t.n))
FROM (
SELECT TOP (1024)
n = ROW_NUMBER() OVER (ORDER BY ao.object_id)
FROM
sys.all_objects ao
) t
WHERE 1 = 1
--AND CONVERT(varchar(10), NCHAR(t.n)) ='À'
;
I found a workaround that appears to do the trick: I was previously trying to replace the ? in the code with &#63 (took out the ; so that it will show the code rather than the output), which didn't work. BUT it seems to work if I use &quest instead.
One thing to note, it seemed that I was originally incorrect in thinking that the issue was only affecting content being read/displayed from the MSSQL DB. Rather, it looks like the same problem was also occurring with static content being "echo'd" by code in the ASP scripts (I'm more of a PHP guy, not sure the correct term is for ASP's equivalent to echo is). Though the links that were hardcoded as static (rather HTML being dynamically output by ASP) were unaffected. Though chancing the ? to &quest worked for those ones too (hardest part was tracking down the file I needed to edit).

MATLab - Database Handle is Empty

I have the following problem. At work we have personal computers running windows7 with MATLab (including the database toolbox), Oracle and so on. I got a new process I should take care about which involves a MATLab script which connects to the oracle database. The scripts works fine on any computer of the department except of mine. Sadly the IT told me that every PC is configured the same and I have to find the misstake for my one.
So i started "debugging" by checking the connection struct MATLab creates when it connects via
conn = database(instance,username,password)
It appears that the content of the structure is equal to every one else, except that the handle is empty:
val =
Instance: '***'
UserName: '*'
Driver: []
URL: []
Constructor: [1x1 com.mathworks.toolbox.database.databaseConnect]
Message: [1x128 char]
Handle: 0
TimeOut: 0
AutoCommit: 'off'
Type: 'Database Object'
on all other systems the handle is set to:
sun.jdbc.odbc.JdbcOdbcConnection
So my question is: Do I have to configure MATLab or is the driver for the JDBC/ODBC is missing? I already checked systems preferences/adminstration/ODBC sources but it seems to by the same as everywhere else.
Do someone might know how I can track down the source of this issue? Any help or hint is highly apprechiated.
Thanks and best regards
stephan
after some research here is the way one can figure it out. It is actually very easy, but I did not try the obvious...
first, if the
connection = database(...)
can not be created, type
connection.message
in the MATLab console. This message will give you additional feedback on the error. In my case the DNS entries for the oracle Databases where empty. After adding them through system preferences it worked as expected.

How to loop a kaplan-meier command in spss syntax?

I'm working in SPSS with this kaplan-meier command:
KM data BY sample
/STATUS=status(0)
/PRINT TABLE MEAN
/PLOT SURVIVAL HAZARD
/TEST LOGRANK BRESLOW TARONE
/COMPARE OVERALL POOLED.
This is no problem but there's a lot of data i have to process and I'm trying to get this in a syntax file together. Can i do a loop of several kaplan-meier commands with data going through a set of variables such as {time0 time1 time2} and sample going through a set such as {sample0 sample1 sample2}.
I tried with DO REPEAT - END REPEAT. But I couldnt get it to work.
DO REPEAT applies to transformation commands. Procedures cannot be placed inside loops. However, if you install the Python Essentials from the SPSS Community site (www.ibm.com/developerworks/spssdevcentral), this is easy to do. If you can provide more details on what you want to loop over, we can explain how to do this.

How do I exploit "EXEC #sql"?

My co-worker is being unsafe with his code and is allowing a user to upload an SQL file to be run on the server.
He strips out any key words in the file such as "EXEC", "DROP", "UPDATE", "INSERT", "TRUNC"
I want to show him the error of his ways by exploiting his EXEC ( #sql )
My first attempt will be with 'EXEXECEC (N''SELECT ''You DRDROPOPped the ball Bob!'')'
But he might filter that all out in a loop.
Is there a way I can exploit my co-worker's code? Or is filtering out the key words enough?
Edit: I got him to check in his code. If the code contains a keyword he does not execute it. I'm still trying to figure out how to exploit this using the binary conversion.
Tell your co-worker he's a moron.
Do an obfuscated SQL query, something like:
select #sql = 0x44524f5020426f627350616e7473
This will need some tweaking depending on what the rest of the code looks like, but the idea is to encode your code in hex and execute it (or rather, let it be executed). There are other ways to obfuscate code to be injected.
You've got a huge security hole there. And the funny part is, this is not even something that needs to be reinvented. The proper way to stop such things from happening is to create and use an account with the correct permissions (eg: can only perform select queries on tables x, y and z).
Have a look at ASCII Encoded/Binary attacks ...
should convince your friend he is doomed.. ;)
And here some help on how to encode the strings ..
Converting a String to HEX in SQL

SSIS suitability

I'm tring to create an SSIS package to import some dataset files, however given that I seem to be hitting a brick
wall everytime I achieve a small part of the task I need to take a step back and perform a sanity check on what I'm
trying to achieve, and if you good people can advise whether SSIS is the way to go about this then I would
appreciate it.
These are my questions from this morning :-
debugging SSIS packages - debug.writeline
Changing an SSIS dts variables
What I'm trying to do is have a For..Each container enumerate over the files in a share on the SQL Server. For each
file it finds a script task runs to check various attributes of the filename, such as looking for a three letter
code, a date in CCYYMM, the name of the data contained therein, and optionally some comments. For example:-
ABC_201007_SalesData_[optional comment goes here].csv
I'm looking to parse the name using a regular expression and put the values of 'ABC', '201007', and
'SalesData' in variables.
I then want to move the file to an error folder if it doesn't meet certain criteria :-
Three character code
Six character date
Dataset name (e.g. SalesData, in this example)
CSV extension
I then want to lookup the Character code, the date (or part thereof), and the Dataset name against a lookup table
to mark off a 'checklist' of received files from each client.
Then, based on the entry in the checklist, I want to kick off another SSIS package.
So, for example I may have a table called 'Checklist' with these columns :-
Client code Dataset SSIS_Package
ABC SalesData NorthSalesData.dtsx
DEF SalesData SouthSalesData.dtsx
If anyone has a better way of achieving this I am interested in hearing about it.
Thanks in advance
That's an interesting scenario, and should be relatively easy to handle.
First, your choice of the Foreach Loop is a good one. You'll be using the Foreach File Enumerator. You can restrict the files you iterate over to be just CSVs so that you don't have to "filter" for those later.
The Foreach File Enumerator puts the filename (full path or just file name) into a variable - let's call that "FileName". There's (at least) two ways you can parse that - expressions or a Script Task. Depends which one you're more comfortable with. Either way, you'll need to create three variables to hold the "parts" of the filename - I'll call them "FileCode", "FileDate", and "FileDataset".
To do this with expressions, you need to set the EvaluateAsExpression property on FileCode, FileDate, and FileDataset to true. Then in the expressions, you need to use FINDSTRING and SUBSTRING to carve up FileName as you see fit. Expressions don't have Regex capability.
To do this in a Script Task, pass the FileName variable in as a ReadOnly variable, and the other three as ReadWrite. You can use the Regex capabilities of .Net, or just manually use IndexOf and Substring to get what you need.
Unfortunately, you have just missed the SQLLunch livemeeting on the ForEach loop: http://www.bidn.com/blogs/BradSchacht/ssis/812/sql-lunch-tomorrow
They are recording the session, however.

Resources