Friday, August 24, 2018

Ansible Parse JSON Array from Register

Related Post: ansible parse json array reply from api

I have an Ansible playlist which registers a return variable:

- name: Create Instance
ec2_instance:
  aws_access_key: "{{access_key}}"
  aws_secret_key: "{{secret_key}}"
  key_name: ***
  instance_type: t2.micro
  security_group: ***
  image_id: ami-39f8215b
  region: ***
register: details

So the details is a JSON object like this:

{
"details": {
    "changed": false, 
    "changes": [], 
    "failed": false, 
    "instance_ids": [
        "i-1111abcde"
    ],
...
}

All I want to do is write a text file with each instance_id in there:

i-1111abcde

I've tried all of the following, none working:

debug:
  var: item
with_items: details['instance_ids']

debug:
  var: item.item
with_items: details['instance_ids']

debug:
  var: details.instance_ids
with_items: details
# This works, but prints the entire JSON array...

Solution

- name: Debug Info
debug:
  var: item
loop: "{{details.instance_ids}}"

- name: Write Temp File
lineinfile:
  path: /tmp/temp.txt
  line: "{{ item }}"
loop: "{{ details.instance_ids }}"

Note: loop is a more modern Ansible concept that with_items or with_*

Solved

Solution

- name: Debug Info
  debug:
    var: item
  loop: "{{details.instance_ids}}"

- name: Write Temp File
lineinfile:
  path: /tmp/temp.txt
  line: "{{ item }}"
loop: "{{ details.instance_ids }}"

Note: loop is a more modern Ansible concept that with_items or with_*


Monday, August 20, 2018

can we have multiple azure active directory tenant mapped to a single subscription?

can we have multiple azure active directory tenant mapped to a single subscription? This is because we want to avoid creating multiple subscriptions for each test environment

Solved

As discussed earlier today, it is only possible to do this on the Classic Portal, which is coming to End of Life as of November 30th. Microsoft doesn't have any plans to introduce this into the new portal anytime soon it seems, and may even plan to keep the relationship 1:1 for Azure going forward.


Sunday, August 19, 2018

Cursor position is wrong in ace-ui edit box

I am using the angular.js version of ui-ace: https://github.com/angular-ui/ui-ace

The cursor in the edit box is off to the right like 10 characters from the text. When hit enter key it does not break where the cursor is.

I have read that ui-ace only behaves correctly with monospace fonts and found a fix from doing a search.

I set this style to fix the issue:

.ace_editor, .ace_editor div {
        font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
    }

This seems to fix the issue when not using any particular theme or mode. But when I set the ui-ace mode: 'html' the cursor position is now off again. I inspected the element in browser and the ui-ace edit box inner containers are using the monospace font.

This is the container in my angular html file:

Saturday, August 18, 2018

datatables + how to combine server side processing code with File export code

This is a datatables example of adding buttons to export data to csv, pdf, excel.... fiddle here

https://datatables.net/extensions/buttons/examples/initialisation/export.html

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );

This is a datatables example of Server-side processing

https://datatables.net/examples/server_side/simple.html

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/server_processing.php"
    } );
} );

Now how do I combine the above code into one, so that i have a data tables that does server side processing and that this is my attempt, but I am not sure where it is wrong, or if indeed I am close.

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/server_processing.php",
        "dom": 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]       
    } );
} );

I have tried various permutations but I am still getting an error in the console Uncaught SyntaxError: Unexpected string Can anyone advise?

This is my real example I am working with

    $(document).ready(function() {
        var dataTable = $('#employee-grid').DataTable( {
            "processing": true,
            "serverSide": true,
            "ajax":{
                url :"employee-grid-data2.php", // json datasource
                type: "post",  // method  , by default get
                error: function(){  // error handling
                    $(".employee-grid-error").html("");
                    $("#employee-grid").append('No data found in the server -- startagain1-index2.php ');
                    $("#employee-grid_processing").css("display","none");

                }
            },
            "dom:" 'Bfrtip',
            "buttons": [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ]
        } );
    } );

Solved

You have the sintax error, change your code in this line:

Incorrect:

"dom:" 'Bfrtip', 

Correct:

"dom" : 'Bfrtip', 

Result: jsfiddle