Symfony 3.4 - SonataUser - Twig - Blank Page - sonata-admin

I have a problem for 2 days, I'm new in Symfony.
I'm using Symfony 3.4.
I create a Backend with Sonata for manage Entities and User.
My backend is ok, but now the twig templates are no longer working. I just have blank page.
Can you help me ? Thanks you in advance.
Here is my files :
composer.json
{
"name": "renicom.com/rcmanager1",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"AppBundle\\": "src/AppBundle",
"Application\\": "src/Application"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-migrations-bundle": "^1.3",
"doctrine/orm": "^2.5",
"friendsofsymfony/rest-bundle": "^2.3",
"incenteev/composer-parameter-handler": "^2.0",
"knplabs/knp-markdown-bundle": "^1.7",
"knplabs/knp-paginator-bundle": "^2.8",
"nelmio/api-doc-bundle": "^3.2",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"sonata-project/admin-bundle": "^3.35",
"sonata-project/block-bundle": "^3.12",
"sonata-project/doctrine-orm-admin-bundle": "^3.6",
"sonata-project/easy-extends-bundle": "^2.5",
"sonata-project/google-authenticator": "^2.1",
"sonata-project/intl-bundle": "^2.5",
"sonata-project/media-bundle": "^3.13",
"sonata-project/user-bundle": "^4.2",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"symfony/templating": "^4.1",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"symfony-scripts": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-install-cmd": [
"#symfony-scripts"
],
"post-update-cmd": [
"#symfony-scripts"
]
},
"config": {
"sort-packages": true
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
},
"branch-alias": null
}
}
AppKernel.php
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new Sonata\CoreBundle\SonataCoreBundle(),
new Sonata\BlockBundle\SonataBlockBundle(),
new Knp\Bundle\MenuBundle\KnpMenuBundle(),
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
new Sonata\AdminBundle\SonataAdminBundle(),
new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
new Sonata\MediaBundle\SonataMediaBundle(),
new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Sonata\IntlBundle\SonataIntlBundle(),
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
];
The Controller
<?php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class AssetController extends Controller
{
/**
* #Route("/objets", name="asset_list_fr")
*/
public function listAction(Request $request, $slug = 'test'){
$asset_list = array();
if ($request->isMethod('GET')){
$params = $request->query;
$category = $this->getDoctrine()
->getRepository('AppBundle:Category');
$categoryP = $category->findOneBy(array('id' => 4));
$type = $this->getDoctrine()
->getRepository('AppBundle:Type');
$typeP = $type->findOneBy(array('id' => 30));
$sector = $this->getDoctrine()
->getRepository('AppBundle:Sector');
$sectorP = null;//$sector->findOneBy(array('id' => '3'));
$em = $this->getDoctrine()->getManager();
$asset_list = $em->getRepository('AppBundle:Asset')
->findBy(['category' => $categoryP]);
$assets = $this->get('knp_paginator')->paginate(
$asset_list, 1
);
}
return $this->render('asset/list.html.twig',
[
'slug' => $slug,
'assets' => $assets,
]);
}
}
My view asset/list.html.twig
{% extends 'base.html.twig' %}
{% block content %}
test
{% endblock %}
my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
parameters:
locale: en
framework:
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
default_locale: '%locale%'
trusted_hosts: ~
session:
handler_id: session.handler.native_file
save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%'
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
auto_mapping: true
mappings:
ApplicationSonataUserBundle: ~
SonataUserBundle: ~
FOSUserBundle: ~
ApplicationSonataMediaBundle: ~
SonataMediaBundle: ~
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager
service:
mailer: fos_user.mailer.twig_swift
user_manager: sonata.user.orm.user_manager
from_email:
address: "test1#test.com" #"%mailer_user%"
sender_name: "test1#test.com" #"%mailer_user%"
sonata_user:
security_acl: true
manager_type: orm
class:
user: Application\Sonata\UserBundle\Entity\User
group: Application\Sonata\UserBundle\Entity\Group
admin:
user:
class: Sonata\UserBundle\Admin\Entity\UserAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
group:
class: Sonata\UserBundle\Admin\Entity\GroupAdmin
controller: SonataAdminBundle:CRUD
translation: SonataUserBundle
sonata_block:
default_contexts: [cms]
blocks:
sonata.user.block.account:
sonata.admin.block.admin_list:
contexts: [admin]
sonata_admin:
title_logo : /images/logo_remicom.png
title: Remicom Admin
sonata_media:
db_driver: doctrine_orm
default_context: default
contexts:
default:
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
- sonata.media.provider.vimeo
formats:
small: { width: 100, quality: 70}
big: { width: 500, quality: 70}
cdn:
server:
path: /uploads/media
filesystem:
local:
directory: "%kernel.root_dir%/../public/uploads/media"
create: false
providers:
image:
resizer: sonata.media.resizer.square
sonata_intl:
timezone:
default: Europe/Paris
knp_paginator:
page_range: 30
My routing.yml
app:
resource: '#AppBundle/Controller/'
type: annotation
admin_area:
resource: '#SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
sonata_user_admin_security:
resource: '#SonataUserBundle/Resources/config/routing/admin_security.xml'
prefix: /admin
sonata_user_admin_resetting:
resource: '#SonataUserBundle/Resources/config/routing/admin_resetting.xml'
prefix: /admin/resetting
I add here 2 screen from the debug section.
The twig debug
The log

finaly I solve the problem. I start a new project and rebuild every part of my Symfony application in the same way, and all work well.
I don't know what was the problem. I certainly forget a little thing but I can't say what.

Related

Unable to get array element from JSON file using Ansible 2.10 version on RedHat

Below is my JSON file
[
{
"?xml": {
"attributes": {
"encoding": "UTF-8",
"version": "1.0"
}
}
},
{
"domain": [
{
"name": "mydom"
},
{
"domain-version": "12.2.1.3.0"
},
{
"server": [
{
"name": "AdminServer"
},
{
"ssl": {
"name": "AdminServer"
}
},
{
"listen-port": "12400"
},
{
"listen-address": "mydom.host1.bank.com"
}
]
},
{
"server": [
{
"name": "myserv1"
},
{
"ssl": [
{
"name": "myserv1"
},
{
"login-timeout-millis": "25000"
}
]
},
{
"listen-port": "22421"
}
]
},
{
"server": [
{
"name": "myserv2"
},
{
"ssl": {
"name": "myserv2"
}
},
{
"reverse-dns-allowed": "false"
},
{
"log": [
{
"name": "myserv2"
},
{
"file-name": "/web/bea_logs/domains/mydom/myserv2/myserv2.log"
}
]
},
{
"listen-port": "12401"
}
]
}
]
}
]
I wish to get the listen-port printed while keeping in mind that the position of listen-port element may change in the array.
I was able to get the listen port on latest ansible version 2.12.2 using the below play
- name: display Listen Port
debug:
msg: "{{ myserver.0.name }} -> {{ cpath[0]['listen-port'] }}"
loop: "{{ jsondata[1].domain }}"
vars:
myserver: "{{ item.server | selectattr('name', 'defined') | list }}"
cpath: "{{ item.server | selectattr('listen-port', 'defined') | list }}"
when: item.server is defined and (item.server | selectattr('listen-port', 'defined') | list ) != []
However, this play does not work on redhat OS where ansible version is 2.10 the latest offering.
Below is the error i recieve:
TASK [create YML for server name with Listen port] ************************************************************
Wednesday 16 March 2022 08:41:06 -0500 (0:00:00.171) 0:00:05.917 *******
skipping: [localhost] => (item={'name': 'mydom'})
skipping: [localhost] => (item={'domain-version': '12.2.1.3.0'})
failed: [localhost] (item={'server': [{'name': 'AdminServer'}, {'ssl': {'name': 'AdminServer'}}, {'listen-port': '12400'}, {'listen-address': 'mydom.host1.bank.com'}]}) => {"ansible_loop_var": "item", "changed": true, "cmd": "echo AdminServer_httpport: 12400>>/web/aes/admin/playbooks/Migrator/wlsdatadump.yml", "delta": "0:00:00.006786", "end": "2022-03-16 08:41:07.175709", "item": {"server": [{"name": "AdminServer"}, {"ssl": {"name": "AdminServer"}}, {"listen-port": "12400"}, {"listen-address": "mydom.host1.bank.com"}]}, "msg": "non-zero return code", "rc": 1, "start": "2022-03-16 08:41:07.168923", "stderr": "/bin/sh: 12400: Bad file descriptor", "stderr_lines": ["/bin/sh: 12400: Bad file descriptor"], "stdout": "", "stdout_lines": []}
skipping: [localhost] => (item={'server': [{'name': 'myserv1'}, {'ssl': [{'name': 'myserv1'}, {'login-timeout-millis': '25000'}]}, {'log': [{'name': 'myserv1'}, {'file-name': '/web/bea_logs/domains/mydom/myserv1/myserv1.log'}]}]})
skipping: [localhost] => (item={'server': [{'name': 'myserv2'}, {'ssl': {'name': 'myserv2'}}, {'reverse-dns-allowed': 'false'}, {'log': [{'name': 'myserv2'}, {'file-name': '/web/bea_logs/domains/mydom/myserv2/myserv2.log'}]}]})
Can you please suggest any other solution?
i suggest you to create a custom filter to avoid multiple choices:
you create a file myfilter.py in a folder filter_plugins (same level your playbook), i have named the plugin customfilter:
#!/usr/bin/python
class FilterModule(object):
def filters(self):
return {
'customfilter': self.customfilter
}
def customfilter(self, json):
result = []
for obj in json[1]['domain']:
for server in obj:
ob = {}
if server == 'server':
for k in obj[server]:
for x in k:
ob.update({x: k[x]})
result.append(ob)
#print(result)
return result
Playbook:
- hosts: localhost
gather_facts: no
vars:
json: "{{ lookup('file', './file.json') | from_json | customfilter }}"
tasks:
- name: display
debug:
msg: "server name: {{ server }} -> filename: {{ filename }} -> listenport: {{ listenport }}"
loop: "{{ json }}"
vars:
server: "{{ item.name }}"
filename: "{{ item.log[1]['file-name'] | d('')}}"
listenport: "{{ item['listen-port'] | d('') }}"
result:
ok: [localhost] => (item={'name': 'AdminServer', 'ssl': {'name': 'AdminServer'}, 'listen-port': '12400', 'listen-address': 'mydom.host1.bank.com'}) => {
"msg": "server name: AdminServer -> filename: -> listenport: 12400"
}
ok: [localhost] => (item={'name': 'myserv1', 'ssl': [{'name': 'myserv1'}, {'login-timeout-millis': '25000'}], 'listen-port': '22421'}) => {
"msg": "server name: myserv1 -> filename: -> listenport: 22421"
}
ok: [localhost] => (item={'name': 'myserv2', 'ssl': {'name': 'myserv2'}, 'reverse-dns-allowed': 'false', 'log': [{'name': 'myserv2'}, {'file-name': '/web/bea_logs/domains/mydom/myserv2/myserv2.log'}], 'listen-port': '12401'}) => {
"msg": "server name: myserv2 -> filename: /web/bea_logs/domains/mydom/myserv2/myserv2.log -> listenport: 12401"
}
the plugin role is to group all dictionaries of each record server in one dictionary and simplify the datas you want to use.
[
{
"name": "AdminServer",
"ssl": {
"name": "AdminServer"
},
"listen-port": "12400",
"listen-address": "mydom.host1.bank.com"
},
{
"name": "myserv1",
"ssl": [
{
"name": "myserv1"
},
{
"login-timeout-millis": "25000"
}
],
"listen-port": "22421"
},
{
"name": "myserv2",
"ssl": {
"name": "myserv2"
},
"reverse-dns-allowed": "false",
"log": [
{
"name": "myserv2"
},
{
"file-name": "/web/bea_logs/domains/mydom/myserv2/myserv2.log"
}
],
"listen-port": "12401"
}
]

XXXXX could not be authenticated to presence-online, Client can not be authenticated, got HTTP status 404

I'm a newbie in Laravel. I have a problem when I tried to built a realtime message with Laravel & ReactJS, Socket.io , Redis
Errors when I start laravel-echo server
file laravel-echo-server.json
{
"authHost": "http://localhost:8000",
"authEndpoint": "/broadcasting/auth",
"clients": [
{
"appId": "XXXXXXXXXX",
"key": "XXXXXXXXXXXXXXXXXXXXX"
}
],
"database": "redis",
"databaseConfig": {
"redis": {},
"sqlite": {
"databasePath": "/database/laravel-echo-server.sqlite"
}
},
"devMode": true,
"host": null,
"port": "6001",
"protocol": "http",
"socketio": {},
"secureOptions": 67108864,
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"subscribers": {
"http": true,
"redis": true
},
"apiOriginAllow": {
"allowCors": false,
"allowOrigin": "",
"allowMethods": "",
"allowHeaders": ""
}
}
file channels.php
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('online', function ($user) {
return $user;
});
In client-side use ReactJS,
file index.js
import Echo from "laravel-echo"
window.io = require('socket.io-client');
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
window.Echo.join(`online`)
.here((users) => {
console.log(users)
})
.joining((user) => {
console.log(user.name);
})
.leaving((user) => {
console.log(user.name);
});
Need some help ... Thanks so much !

How to refer to list during with_dict loop

I am trying to build playbook that dynamically queries Windows' registry to detect installed instances of SQL Server (or anything else), its version, location, etc. and do X action for every instance. This works ok if only one SQL instance is installed but I am not sure how to achieve this in multi-instance environment as I am mixing dicts and list and I am not sure how to solve this..
As a simple example playbook below detects installed SQL instances based on reg keys and checks version of SQL for each instance. I would like to out the info on per instance basis (or even better put this into dict variable so I can use it later and add more details based on other reg keys).
Problem is that some of the returned data is a list and I am not sure how to add it to the loop (or add it to dict where key is the instance for example).
Code:
- name: 'Go to Windows registry and check if any SQL instance is installed - using win_reg_stat module'
win_reg_stat:
path: HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL
register: reg_InstalledInstances
- name: 'Go to Windows registry and for each installed instance get its version number'
win_reg_stat:
path: HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\{{item.value.raw_value}}\MSSQLServer\CurrentVersion
name: CurrentVersion
with_dict: '{{reg_InstalledInstances.properties}}'
register: reg_CurrentVersion
- debug:
msg:
- '{{reg_CurrentVersion}}'
- name: 'Show all the details'
debug:
msg:
- 'Hostname: {{inventory_hostname}}'
- 'SQL Instance: {{item.key}}'
- 'SQL Instance in Registry: {{item.value.raw_value}}'
#- 'CurrentVersion: {{reg_CurrentVersion.results.raw_value}}'
with_dict: '{{reg_InstalledInstances.properties}}'
- name:
debug:
msg:
- '{{reg_CurrentVersion}}'
Problem:
I am not sure how to refer reg_CurrentVersion into the loop - in the loop (i tried {{reg_CurrentVersion.results.item.raw_value}} as well):
...
- 'CurrentVersion: {{reg_CurrentVersion.results.raw_value}}'
with_dict: '{{reg_InstalledInstances.properties}}'
results in:
the task includes an option with an undefined variable. The error was: 'list object' has no attribute 'raw_value'
reg_CurrentVersion on its own works fine and looks like this:
ok: [gbltcdevcmdr01] => {
"msg": [
{
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"exists": true,
"failed": false,
"item": {
"key": "SQL2014",
"value": {
"raw_value": "MSSQL12.SQL2014",
"type": "REG_SZ",
"value": "MSSQL12.SQL2014"
}
},
"raw_value": "12.0.6024.0",
"type": "REG_SZ",
"value": "12.0.6024.0"
},
{
"ansible_loop_var": "item",
"changed": false,
"exists": true,
"failed": false,
"item": {
"key": "SQL2016",
"value": {
"raw_value": "MSSQL13.SQL2016",
"type": "REG_SZ",
"value": "MSSQL13.SQL2016"
}
},
"raw_value": "13.2.5026.0",
"type": "REG_SZ",
"value": "13.2.5026.0"
},
{
"ansible_loop_var": "item",
"changed": false,
"exists": true,
"failed": false,
"item": {
"key": "MSSQLSERVER",
"value": {
"raw_value": "MSSQL11.MSSQLSERVER",
"type": "REG_SZ",
"value": "MSSQL11.MSSQLSERVER"
}
},
"raw_value": "11.0.7001.0",
"type": "REG_SZ",
"value": "11.0.7001.0"
},
{
"ansible_loop_var": "item",
"changed": false,
"exists": true,
"failed": false,
"item": {
"key": "SQL2017",
"value": {
"raw_value": "MSSQL14.SQL2017",
"type": "REG_SZ",
"value": "MSSQL14.SQL2017"
}
},
"raw_value": "14.0.1000.169",
"type": "REG_SZ",
"value": "14.0.1000.169"
}
]
}
]
}
EDIT:
at the moment if I run the initial code:
...
- name: 'Show all the details'
debug:
msg:
- 'Hostname: {{inventory_hostname}}'
- 'SQL Instance: {{item.key}}'
- 'SQL Instance in Registry: {{item.value.raw_value}}'
#- 'CurrentVersion: {{reg_CurrentVersion.results.raw_value}}'
with_dict: '{{reg_InstalledInstances.properties}}'
I got this:
ok: [testhost] => (item={'key': 'SQL2014', 'value': {'raw_value': 'MSSQL12.SQL2014', 'value': 'MSSQL12.SQL2014', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2014",
"SQL Instance in Registry: MSSQL12.SQL2014"
]
}
ok: [testhost] => (item={'key': 'SQL2016', 'value': {'raw_value': 'MSSQL13.SQL2016', 'value': 'MSSQL13.SQL2016', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2016",
"SQL Instance in Registry: MSSQL13.SQL2016"
]
}
ok: [testhost] => (item={'key': 'MSSQLSERVER', 'value': {'raw_value': 'MSSQL11.MSSQLSERVER', 'value': 'MSSQL11.MSSQLSERVER', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: MSSQLSERVER",
"SQL Instance in Registry: MSSQL11.MSSQLSERVER"
]
}
ok: [testhost] => (item={'key': 'SQL2017', 'value': {'raw_value': 'MSSQL14.SQL2017', 'value': 'MSSQL14.SQL2017', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2017",
"SQL Instance in Registry: MSSQL14.SQL2017"
]
}
I would like to simply add reg_CurrentVersion.results.raw_value as an extra line for each instance. Something like below:
ok: [testhost] => (item={'key': 'SQL2014', 'value': {'raw_value': 'MSSQL12.SQL2014', 'value': 'MSSQL12.SQL2014', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2014",
"SQL Instance in Registry: MSSQL12.SQL2014"
"CurrentVersion: 12.0.6024.0"
]
}
ok: [testhost] => (item={'key': 'SQL2016', 'value': {'raw_value': 'MSSQL13.SQL2016', 'value': 'MSSQL13.SQL2016', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2016",
"SQL Instance in Registry: MSSQL13.SQL2016"
"CurrentVersion: 13.2.5026.0"
]
}
ok: [testhost] => (item={'key': 'MSSQLSERVER', 'value': {'raw_value': 'MSSQL11.MSSQLSERVER', 'value': 'MSSQL11.MSSQLSERVER', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: MSSQLSERVER",
"SQL Instance in Registry: MSSQL11.MSSQLSERVER"
"CurrentVersion: 11.0.7001.0"
]
}
ok: [testhost] => (item={'key': 'SQL2017', 'value': {'raw_value': 'MSSQL14.SQL2017', 'value': 'MSSQL14.SQL2017', 'type': 'REG_SZ'}}) => {
"msg": [
"Hostname: testhost",
"SQL Instance: SQL2017",
"SQL Instance in Registry: MSSQL14.SQL2017"
"CurrentVersion: 14.0.1000.169"
]
}
PS. Is there a way to build dict and append new values to it later on?
Tomasz
Q: "Is there a way to build a dictionary and append new values to it later on?"
A: Yes. It's possible. Let's create the dictionary with the data
- set_fact:
mylist: "{{ reg_CurrentVersion.results|
json_query('[].{instance: item.key,
registry: item.value.raw_value,
version: raw_value}') }}"
- debug:
var: mylist
gives
"mylist": [
{
"instance": "SQL2014",
"registry": "MSSQL12.SQL2014",
"version": "12.0.6024.0"
},
{
"instance": "SQL2016",
"registry": "MSSQL13.SQL2016",
"version": "13.2.5026.0"
},
{
"instance": "MSSQLSERVER",
"registry": "MSSQL11.MSSQLSERVER",
"version": "11.0.7001.0"
},
{
"instance": "SQL2017",
"registry": "MSSQL14.SQL2017",
"version": "14.0.1000.169"
}
]
Append hostname to each dictionary
- set_fact:
mylist2: "{{ mylist2|default([]) +
[item|combine({'hostname': inventory_hostname})] }}"
loop: "{{ mylist }}"
- debug:
var: mylist2
gives
"mylist2": [
{
"hostname": "localhost",
"instance": "SQL2014",
"registry": "MSSQL12.SQL2014",
"version": "12.0.6024.0"
},
{
"hostname": "localhost",
"instance": "SQL2016",
"registry": "MSSQL13.SQL2016",
"version": "13.2.5026.0"
},
{
"hostname": "localhost",
"instance": "MSSQLSERVER",
"registry": "MSSQL11.MSSQLSERVER",
"version": "11.0.7001.0"
},
{
"hostname": "localhost",
"instance": "SQL2017",
"registry": "MSSQL14.SQL2017",
"version": "14.0.1000.169"
}
]

How to access register variable in task

This is my output of EC2 instance. I am trying to access "instance_type".
And here is my task.
ec2:
key_name: redhat
group: MY_EC2
instance_type: t2.micro
image: ami-cfe4b2b0
region: us-east-1
zone: us-east-1a
wait: true
exact_count: 1
count_tag:
name: MyProjectInstances
instance_tags:
name: Ansible
register: ec2
- set_fact:
inst: "{{ ec2 }}"
- debug:
msg: "{{ inst }}"
I can reach Instances block through trying this.
debug:
msg: "{{ inst.instances }}" but cannot go further, getting error of undefined variable.
#
Output:
ok: [localhost] => {
"msg": {
"changed": true,
"failed": false,
"instance_ids": [
"i-0be089202b191769e"
],
"instances": [
{
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {
"/dev/xvda": {
"delete_on_termination": true,
"status": "attached",
"volume_id": "vol-02b129004f1a5fb89"
}
},
"dns_name": "ec2-34-204-84-170.compute-1.amazonaws.com",
"ebs_optimized": false,
"groups": {
"sg-06c09a2c83d7b1a96": "MY_EC2"
},
"hypervisor": "xen",
"id": "i-0be089202b191769e",
"image_id": "ami-cfe4b2b0",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "redhat",
"launch_time": "2018-07-15T14:34:43.000Z",
"placement": "us-east-1a",
"private_dns_name": "ip-172-31-35-24.ec2.internal",
"private_ip": "172.31.35.24",
"public_dns_name": "ec2-34-204-84-170.compute-1.amazonaws.com",
"public_ip": "34.204.84.170",
"ramdisk": null,
"region": "us-east-1",
"root_device_name": "/dev/xvda",
"root_device_type": "ebs",
"state": "running",
"state_code": 16,
"tags": {
"name": "Ansible"
},
"tenancy": "default",
"virtualization_type": "hvm"
}
Please try as below::
- name: Get instance Type
debug: msg={{ inst | json_query('instances[].instance_type') }}

loopback angular sdk get all users with a certain role

I'm currently stuck on getting all the users with certain role, for example admin users, in one angular SDK controller.
according to the docs of strongloop. what I did was:
User.find({
filter: {
include: [{'relation':'roles', 'scope': {
where:{
name:'admin',
}}
}],
},
}, function(list) {
console.log(list);
});
But the list i got is all the users, the non-admin users are included too. On the server side it is the default codes, i didn't change them.
{
"name": "user",
"plural": "Users",
"base": "User",
"properties": {
},
"relations": {
"roles": {
"type": "belongsTo",
"model": "RoleMapping",
"foreignKey": "principalId"
}
},
"acls": [],
"methods": []
}
Could you tell me what I made wrong? I don't want to loop through all the "list" from that query and filter the admin users, because it is a very huge list of users, but admin is for only 2 or 3 persons.
Here is the solution of what i did, from the common/models/user.js, i created a remotemethod, called "getUsersByRole", and only accept "role", which is the name of the role:
User.remoteMethod('getUsersByRole', {
accepts: [
{ arg: 'role', type: 'string', required: true },
],
returns: {arg: 'users', type: 'string'},
http: {
verb: 'get',
path: '/byrole/:role'
}
});
then here is the function of it:
User.getUsersByRole = function(role, cb) {
var loopback = require('loopback');
var Role = loopback.getModel('Role');
var userIdList = [];
Role.findOne({include:'principals', where: {name:role}}, function(err, role) {
role.principals(function(err, principals) {
for (var i = 0; i < principals.length; i++) {
userIdList.push(parseInt(principals[i].principalId));
}
if (userIdList.length > 0) {
User.find({where: {id: {inq: userIdList}}}, function(err, users) {
cb(err, users);
});
} else {
cb(err, false);
}
});
});
}
then run the lb-ng command to generate the service for angular client side, then run:
User.getUsersByRole({role:rolename}, function(list) {
});
in the controller.
Can you run the query from the role instead?
Role.find({
filter: {
where: {name:'admin'},
include: {'relation':'users'}
},
}, function(list) {
console.log(list);
});

Resources