question stringlengths 11 28.2k | answer stringlengths 26 27.7k | tag stringclasses 130
values | question_id int64 935 78.4M | score int64 10 5.49k |
|---|---|---|---|---|
I want to run an Ansible action on the condition that a shell command doesn't return the expected output. ogr2ogr --formats pretty-prints a list of compatible file formats. I want to grep the formats output, and if my expected file formats aren't in the output, I want to run a command to install these components. Does ... | First, please make sure you are using Ansible 1.3 or later. Ansible is still changing pretty quickly from what I can see, and a lot of awesome features and bug fixes are crucial.
As for checking, you can try something like this, taking advantage of grep's exit code:
- name: check if proper ogr formats set up
shell: o... | Ansible | 19,942,269 | 27 |
I have python2.7 and python3.5 in my ansible server , while executing playbooks it is using python2.7. I wanted ansible to use python3.5 when executing playbooks.
in order:
1 have set export path.
2 also changed default interpreter path in ansible.cfg as well.
3 have given specific interpretor path in hostsf... | If you want to set the Python interpreter for individual hosts and groups, set the ansible_python_interpreter inventory variable.
If however, you want to set the Python interpreter for global use, then set the interpreter_python key in the [defaults] section in the configuration file ansible.cfg.
For a complete list of... | Ansible | 59,380,824 | 26 |
I'm struggling to install Ansible Python package on my Windows 10 machine.
I don't need Ansible to run on my machine, this is purely for development purpose on my Windows host. All commands will later be issued on a Linux machine.
After running:
pip install ansible
I get the following exception:
Command "c:\users\eva... | Installing Ansible on Windows is cumbersome. My advice is not a direct solution on how to install Ansible on Windows, but rather a workaround.
I use a Docker container with Ansible for developing playbooks on my Windows machine. You'd need Docker for Windows on your machine.
Here's the Dockerfile:
FROM alpine:3.7
ENV... | Ansible | 51,167,099 | 26 |
I'm trying to filter properties of an object in jmespath based on the value of a subproperty and want to include only those properties where the subproperty is set to a specific value.
Based on this example data:
{
"a": {
"feature": {
"enabled": true,
}
},
"b": {
},
"c": {
"feature": {
... | With dict2items filter in Ansible 2.5 and later, you can do it with:
- debug:
msg: "{{ dict(my_data | dict2items | json_query('[?value.feature.enabled].[key, value]')) }}"
The result:
"msg": {
"a": {
"feature": {
"enabled": true
}
}
}
| Ansible | 41,579,581 | 26 |
Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination?
For example, our inventory files are split up by service type:
[dev:children]
dev_a
dev_b
[dev_a]
my.host.int.abc.com
[dev_b]
my.host.int.xyz.com
[prod:children]
prod_a
prod_b
[prod_a]
my.host.abc.c... | Do the same trick from before, but instead of all, pass the group name you want to list:
ansible (group name here) -i (inventory file here) --list-hosts
| Ansible | 37,623,849 | 26 |
In Ansible, in a role, I have vars files like this:
vars/
app1.yml
app2.yml
Each file contains vars specific to an app/website like this:
name: app1
git_repo: https://github.com/philgyford/app1.git
# ...
Ideally, without the task knowing in advance which apps have variable files, I'd like to end up with an ar... | You can not do that. Variables will always override variables with the same name. The only thing you could do with this exact setup is to write your own vars plugin which reads those files and merges them into an array.
If you are open to change the structure of your apps definition you can use a hash and set your hash... | Ansible | 35,554,415 | 26 |
I have a json file in the same directory where my ansible script is. Following is the content of json file:
{ "resources":[
{"name":"package1", "downloadURL":"path-to-file1" },
{"name":"package2", "downloadURL": "path-to-file2"}
]
}
I am trying to to download these packages using get_url. Foll... | You have to add a from_json jinja2 filter after the lookup:
version_file: "{{ lookup('file','/home/shasha/devOps/tests/packageFile.json') | from_json }}"
| Ansible | 35,403,769 | 26 |
play_hosts is a list of all machines for a play. I want to take these and use something like format() to rewrite them like rabbitmq@%s and then join them together with something like join(). So:
{{ play_hosts|format(???)|join(', ') }}
All the examples of format use piping where the input is the format string and not a... | In ansible you can use regex_replace filter:
{{ play_hosts | map('regex_replace', '^(.*)$', 'rabbitmq@\\1') | list }}
| Ansible | 35,183,744 | 26 |
I need to create a single file with the contents of a single fact in Ansible. I'm currently doing something like this:
- template: src=templates/git_commit.j2 dest=/path/to/REVISION
My template file looks like this:
{{ git_commit }}
Obviously, it'd make a lot more sense to just do something like this:
- inline_templa... | Another option to the lineinfile module (as given by udondan's answer) would be to use the copy module and specify the content rather than a source local to the Ansible host.
An example task would look something like:
- name: Copy commit ref to file
copy:
content: "{{ git_commit }}"
dest: /path/to/REVISION
I... | Ansible | 33,768,690 | 26 |
I am trying to run an Ansible playbook against a server using an account other than the one I am logged on the control machine. I tried to specify an ansible_user in the inventory file according to the documentation on Inventory:
[srv1]
192.168.1.146 ansible_connection=ssh ansible_user=user1
However Ansible called wit... | You're likely running into a common issue: the published ansible docs are for the development version (2.0 right now), and we don't keep the old ones around. It's a big point of contention... Assuming you're using something pre-2.0, the inventory var name you need is ansible_ssh_user. ansible_user works in 2.0 (as does... | Ansible | 33,061,524 | 26 |
I would like to replace /etc/nginx/sites-enabled with a symlink to my repo. I'm trying to do this using file module, but that doesn't work as the file module doesn't remove a directory with force option.
- name: setup nginx sites-available symlink
file: path=/etc/nginx/sites-available src=/repo/etc/nginx/sites-availa... | When you take your action, it's actually things:
delete a folder
add a symlink in its place
This is probably also the cleanest way to represent in Ansible:
tasks:
- name: remove the folder
file: path=/etc/nginx/sites-available state=absent
- name: setup nginx sites-available symlink
file: path=/etc/ngin... | Ansible | 27,006,925 | 26 |
I'm writing my k8s upgrade ansible playbook, and within that I need to do apt-mark unhold kubeadm. Now, I am trying to avoid using the ansible command or shell module to call apt if possible, but the apt hold/unhold command does not seem to be supported by neither package nor apt modules.
Is it possible to do apt-mark... | You can use the ansible.builtin.dpkg_selections module for this.
Note that unhold translates to install in this context.
- name: Hold kubeadm
ansible.builtin.dpkg_selections:
name: kubeadm
selection: hold
- name: Unhold kubeadm
ansible.builtin.dpkg_selections:
name: kubeadm
selection: install
| Ansible | 63,982,903 | 25 |
I have one playbook and in this playbook, there are so many tasks. I need to know which task has taken how much time?
Is there any solution?
| Add callbacks_enabled = profile_tasks in the [defaults] section in your ansible.cfg.
(Or callback_whitelist for Ansible < 2.11.)
Here is my ansible.cfg
[defaults]
inventory = hosts
callbacks_enabled = profile_tasks
deprecation_warnings = False
Here is my playbook
- hosts: localhost
gather_facts: true
tasks:
- ... | Ansible | 61,948,417 | 25 |
I'm running a playbook which defined several packages to install via apt:
- name: Install utility packages common to all hosts
apt:
name: "{{ item }}"
state: present
autoclean: yes
with_items:
- aptitude
- jq
- curl
- git-core
- at
...
A r... | You can code the array in YAML style to make it more readable:
- name: Install utility packages common to all hosts
apt:
name:
- aptitude
- jq
- curl
- git-core
- at
state: present
autoclean: yes
| Ansible | 52,743,147 | 25 |
That is to say: how to evaluate the password lookup only once?
- name: Demo
hosts: localhost
gather_facts: False
vars:
my_pass: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"
tasks:
- debug:
msg: "{{ my_pass }}"
- debug:
msg: "{{ my_pass }}"
- debug:
msg: "{{ m... | Use set_fact to assign permanent fact:
- name: Demo
hosts: localhost
gather_facts: False
vars:
pwd_alias: "{{ lookup('password', '/dev/null length=15 chars=ascii_letters') }}"
tasks:
- set_fact:
my_pass: "{{ pwd_alias }}"
- debug:
msg: "{{ my_pass }}"
- debug:
msg: "{{ my... | Ansible | 46,732,703 | 25 |
I have an ansible playbook to kill running processes and works great most of the time!, however, from time to time we find processes that just can't be killed so, "wait_for" gets to the timeout, throws an error and it stops the process.
The current workaround is to manually go into the box, use "kill -9" and run the a... | You could ignore errors on wait_for and register the result to force kill failed items:
- name: Get running processes
shell: "ps -ef | grep -v grep | grep -w {{ PROCESS }} | awk '{print $2}'"
register: running_processes
- name: Kill running processes
shell: "kill {{ item }}"
with_items: "{{ running_processes.s... | Ansible | 46,515,704 | 25 |
I find it hard to believe there isn't anything that covers this use case but my search has proved fruitless.
I have a line in /etc/fstab to mount a drive that's no longer available:
//archive/Pipeline /pipeline/Archives cifs ro,credentials=/home/username/.config/cifs 0 0
What I want is to change it to
#//archive/Pi... | You can use the replace module for your case:
---
- hosts: slurm
remote_user: root
tasks:
- name: Comment out pipeline archive in fstab
replace:
dest: /etc/fstab
regexp: '^//archive/pipeline'
replace: '#//archive/pipeline'
tags: update-fstab
It will replace all occurrences ... | Ansible | 39,239,602 | 25 |
I am using Ansible to deploy a Django website into my servers (production, staging, etc), and I would like to get a notification (via slack in this case) if and only if any task fails.
I can only figure out how to do it if a specified task fails (so I guess I could add a handler to all tasks), but intuition tells me th... | I don't think a handler is a solution, because a handler will only be notified if the task reports a changed state. On a failed state the handler will not be notified.
Also, handlers by default will not be fired if the playbook failed. But that can be changed. For that you will need to set this in your ansible.cfg:
for... | Ansible | 35,892,455 | 25 |
I see that files can supply variables to Ansible through the command line using --extra-vars "@some_file.json", or variables can be set in strings as key=value. Is it possible to do both? And if so, what's the syntax?
| Specify both but separately.
--extra-vars "@some_file.json" --extra-vars "key=value"
| Ansible | 34,959,691 | 25 |
What's the sane way run a task only if the host belongs to one or more groups?
Currently, I'm using a boolean within the relevant group, e.g.:
Inventory file
[db_servers:vars]
copy_connection_string=true
Task
- name: Copy db connection string file
synchronize: # ...
when: copy_connection_string is defined
What's ... | Run task when a host server is a member of a specific group
Ansible contains special or magic variables - one of the most common is group_names which is a list (array) of all the groups the current host is in.
- name: Copy db connection string file
synchronize: # ...
when: "'db_servers' in group_names"
The above A... | Ansible | 32,988,878 | 25 |
What is the best practice for running one role with different set of parameters?
I need to run one application(docker container) multiple times on one server with different environment variables for each.
| There's limitations in the Ansible docs when it comes to this kind of thing - if there's an official best practice, I haven't come across it.
One good way that keeps your playbooks nice and readable is running several different plays against the host and calling the role with different parameters in each.
The role: foo... | Ansible | 32,802,956 | 25 |
What is the best way to get the main network interface name for a Linux server with Ansible? This is often/usually eth0 but we can't always assume this is the case and it would be better to identify this dynamically.
We are configuring the firewall with Ansible so we need to be able to issue the interface name as part ... | That should be {{ ansible_default_ipv4.interface }}. This is a system fact.
| Ansible | 32,189,385 | 25 |
I would like to build an output that shows the key and value of a variable.
The following works perfectly ...
# Format in Ansible
msg="{{ php_command_result.results | map(attribute='item') | join(', ') }}"
# Output
{'value': {'svn_tag': '20150703r1_6.36_homeland'}, 'key': 'ui'}, {'value': {'svn_tag': '20150702r1_6.36... | Using Jinja statements:
- set_fact:
php_command_result:
results: [{"value":{"svn_tag":"20150703r1_6.36_homeland"},"key":"ui"},{"value":{"svn_tag":"20150702r1_6.36_homeland"},"key":"api"}]
- debug:
msg: "{% for result in php_command_result.results %}\
{{ result.key }} - {{ result.value.svn_tag }} ... | Ansible | 31,685,125 | 25 |
I'm using Ansible with Jinja2 templates, and this is a scenario that I can't find a solution for in Ansible's documentation or googling around for Jinja2 examples. Here's the logic that I want to achieve in Ansible:
if {{ existing_ansible_var }} == "string1"
new_ansible_var = "a"
else if {{ existing_ansible_var }} ==... | If you just want to output a value in your template depending on the value of existing_ansible_var you simply could use a dict and feed it with existing_ansible_var.
{{ {"string1": "a", "string2": "b"}[existing_ansible_var] | default("") }}
You can define a new variable the same way:
{% set new_ansible_var = {"string1... | Ansible | 30,637,054 | 25 |
I have a C++ program hosted in Bitbucket git repository that I'm compiling with CMake. The current play can be seen below. It works fine except build-task is run every time the play is run. Instead I'd like build-task to run only when new software version is pulled by git-module. How I can tell in build-task if clone-t... | You can register variable with output of clone task and invoke build task when state of clone task is changed
For example:
---
# tasks of role: foo
- name: clone repository
git: repo=git@bitbucket.org:foo/foo.git
dest={{ foo.dir }}
accept_hostkey=yes
register: gitclone
- name: create build dir
fil... | Ansible | 23,014,713 | 25 |
When I try to install ansible role, I see this exception.
$ ansible-galaxy install zzet.postgresql
Traceback (most recent call last):
File "/Users/myHomeDir/.homebrew/Cellar/ansible/1.4.3/libexec/bin/ansible-galaxy", line 34, in <module>
import yaml
ImportError: No module named yaml
OS: Mac Os Maverick
Ansible: ... | Based on the error message, it tries to import the python module yaml but cannot find it. The yaml module is called pyyaml when you install it with pip:
pip install pyyaml
If pip is not installed on your mac then you can install it as,
easy_install pip
| Ansible | 20,966,921 | 25 |
OK, strange question. I have SSH forwarding working with Vagrant. But I'm trying to get it working when using Ansible as a Vagrant provisioner.
I found out exactly what Ansible is executing, and tried it myself from the command line, sure enough, it fails there too.
[/common/picsolve-ansible/u12.04%]ssh -o HostName=12... | As of ansible 1.5 (devel aa2d6e47f0) last updated 2014/03/24 14:23:18 (GMT +100) and Vagrant 1.5.1 this now works.
My Vagrant configuration contains the following:
config.vm.provision "ansible" do |ansible|
ansible.playbook = "../playbooks/basho_bench.yml"
ansible.sudo = true
ansible.host_key_checking = false... | Ansible | 20,952,689 | 25 |
I want to use a public aws keypair .pem file for running ansible playbooks. I want to do this without changing my ~/.ssh/id_rsa.pub and I can't create a new keypair from my current ~/.ssh/id_rsa.pub and apply it to the ec2 instances I am trying to change.
$ ansible --version
ansible 1.9.6
configured module search pa... | Ok little mistakes I guess you can't have spaces in host file variables and need to define the group you are applying the vars to. This hosts file works with it all:
[dashboard:vars]
ansible_ssh_private_key_file=./mykeypair.pem
[dashboard]
1.2.3.4 dashboard_domain=my.domain.info
| Ansible | 42,123,317 | 24 |
I have to parse some files and convert them to some predefined datatypes.
Haskell seems to be providing two packages for that:
attoparsec
parsec
What is the difference between the two of them and which one is better suited for parsing a text file according to some rules?
| Parsec
Parsec is good for "user-facing" parsers: things where you have a bounded amount of input but error messages matter. It's not terribly fast, but if you have small inputs this shouldn't matter. For example, I would choose Parsec for virtually any programming language tools since--in absolute terms--even the large... | Parsec | 19,208,231 | 82 |
There seems to be a consensus that you should use Parsec as an applicative rather than a monad. What are the benefits of applicative parsing over monadic parsing?
style
performance
abstraction
Is monadic parsing out?
| The main difference between monadic and applicative parsing is in how sequential composition is handled. In the case of an applicative parser, we use (<*>), whereas with a monad we use (>>=).
(<*>) :: Parser (a -> b) -> Parser a -> Parser b
(>>=) :: Parser a -> (a -> Parser b) -> Parser b
The monadic approach is more ... | Parsec | 7,861,903 | 76 |
When writing a parser in a parser combinator library like Haskell's Parsec, you usually have 2 choices:
Write a lexer to split your String input into tokens, then perform parsing on [Token]
Directly write parser combinators on String
The first method often seems to make sense given that many parsing inputs can be und... | The most important difference is that lexing will translate your input domain.
A nice result of this is that
You do not have to think about whitespace anymore. In a direct (non-lexing) parser, you have to sprinkle space parsers in all places where whitespace is allowed to be, which is easy to forget and it clutters yo... | Parsec | 15,216,202 | 49 |
Text
Text.Parsec
Text.Parsec.ByteString
Text.Parsec.ByteString.Lazy
Text.Parsec.Char
Text.Parsec.Combinator
Text.Parsec.Error
Text.Parsec.Expr
Text.Parsec.Language
Text.Parsec.Perm
Text.Parsec.Pos
Text.Parsec.Prim
Text.Parse... | At the moment there are two widely used major versions of Parsec: Parsec 2 and
Parsec 3.
My advice is simply to use the latest release of Parsec 3. But if you want to
make a conscientious choice, read on.
New in Parsec 3
Monad Transformer
Parsec 3 introduces a monad transformer, ParsecT, which can be used to combine
pa... | Parsec | 6,029,371 | 44 |
Using Parsec 3.1, it is possible to parse several types of inputs:
[Char] with Text.Parsec.String
Data.ByteString with Text.Parsec.ByteString
Data.ByteString.Lazy with Text.Parsec.ByteString.Lazy
I don't see anything for the Data.Text module. I want to parse Unicode content without suffering from the String inefficie... | Since Parsec 3.1.2 support of Data.Text is built-in!
See http://hackage.haskell.org/package/parsec-3.1.2
If you are stuck with older version, the code snippets in other answers are helpful, too.
| Parsec | 4,064,532 | 37 |
Around 6 years ago, I benchmarked my own parser combinators in OCaml and found that they were ~5× slower than the parser generators on offer at the time. I recently revisited this subject and benchmarked Haskell's Parsec vs a simple hand-rolled precedence climbing parser written in F# and was surprised to find the F# t... | I've come up with a Haskell solution that is 30× faster than the Haskell solution you posted (with my concocted test expression).
Major changes:
Change Parsec/String to Attoparsec/ByteString
In the fact function, change read & many1 digit to decimal
Made the chainl1 recursion strict (remove $! for the lazier version).... | Parsec | 4,559,399 | 37 |
To learn how to write and parse a context-free grammar I want to choose a tool. For Haskell, there are two big options: Happy, which generates a parser from a grammar description and *Parsec, which allows you to directly code a parser in Haskell.
What are the (dis)advantages of either approach?
| External vs internal DSL
The parser specification format for Happy is an external DSL, whereas with Parsec you have the full power of Haskell available when defining your parsers. This means that you can for example write functions to generate parsers, use Template Haskell and so on.
Precedence rules
With Happy, you c... | Parsec | 7,269,025 | 28 |
I'm trying to make a parser for a simple functional language, a bit like Caml, but I seem to be stuck with the simplest things.
So I'd like to know if there are some more complete examples of parsec parsers, something that goes beyond "this is how you parse 2 + 3". Especially function calls in terms and suchlike.
And I... | Hmm,
*Expr> parse expr "" "a(6)"
Right (FuncCall "a" [Number 6.0])
that part works for me after filling out the missing pieces.
Edit: I filled out the missing pieces by writing my own float parser, which could parse integer literals. The float parser from Text.Parsec.Token on the other hand, only parses literals with ... | Parsec | 8,218,529 | 25 |
What is the difference between "try" and "lookAhead" functions in parsec?
| The combinators try and lookAhead are similar in that they both let Parsec "rewind", but they apply in different circumstances. In particular, try rewinds failure while lookAhead rewinds success.
By the documentation, try "pretends that it hasn't consumed any input when an error occurs" while lookAhead p "parses p with... | Parsec | 20,020,350 | 24 |
I'm just starting with Parsec (having little experience in Haskell), and I'm a little confused about using monads or applicatives. The overall feel I had after reading "Real World Haskell", "Write You a Haskell" and a question here is that applicatives are preferred, but really I have no idea.
So my questions are:
Wha... | It might be worth paying attention to the key semantic difference between Applicative and Monad, in order to determine when each is appropriate. Compare types:
(<*>) :: m (s -> t) -> m s -> m t
(>>=) :: m s -> (s -> m t) -> m t
To deploy <*>, you choose two computations, one of a function, the other of an argument, th... | Parsec | 38,707,813 | 23 |
I'm trying to get data from a webpage that serves a XML file periodically with stock market quotes (sample data). The structure of the XML is very simple, and is something like this:
<?xml version="1.0"?>
<Contents>
<StockQuote Symbol="PETR3" Date="21-12-2010" Time="13:20" Price="23.02" />
</Contents>
(it's more tha... | There are plenty of XML libraries written for Haskell that can do the parsing for you. I recommend the library called xml (see http://hackage.haskell.org/package/xml). With it, you can simply write e.g.:
let contents = parseXML source
quotes = concatMap (findElements $ unqual "StockQuote") (onlyElems contents)
... | Parsec | 4,619,206 | 18 |
The indents package for Haskell's Parsec provides a way to parse indentation-style languages (like Haskell and Python). It redefines the Parser type, so how do you use the token parser functions exported by Parsec's Text.Parsec.Token module, which are of the normal Parser type?
Background
Parsec is a parser combinator... | What are you trying to do?
It sounds like you want to have your parsers defined everywhere as being of type
Parser Something
(where Something is the return type) and to make this work by hiding and redefining the Parser type which is normally imported from Text.Parsec.String or similar. You still need to import some of... | Parsec | 15,315,624 | 18 |
Using Control.Applicative is very useful with Parsec, but you need to always hide <|> and similar objects as they conflict with Parsec's own:
import Control.Applicative hiding ((<|>), many, optional)
import Text.Parsec.Combinator
import Text.Parsec
Alternatively, as Antal S-Z points out, you can hide the Parsec versio... | It's for historic reasons. The Parsec library predates the discovery of applicative functors and so it wasn't designed with them in mind. And I guess no one has taken the time to update Parsec to use Control.Applicative. There is no deep fundamental reason for not doing it.
| Parsec | 15,767,978 | 18 |
I'm parsing an expression using Parsec and I want to keep track of variables in these expressions using the user state in Parsec. Unfortunately I don't really get how to do it.
Given the following code:
import Data.Set as Set
inp = "$x = $y + $z"
data Var = V String
var = do char '$'
n <- many1 letter
let... | Unfortunately, Yuras' suggestion of updateParserState is not optimal (you'd use that function if you're looking to modify Parsec's internal state as well); instead you should pass a function that works over your custom user state (i.e. of type u -> u) to modifyState, such as in this example:
expr = do
x <- identifie... | Parsec | 6,477,541 | 17 |
The documentation for Parsec.Expr.buildExpressionParser says:
Prefix and postfix operators of the same precedence can only occur
once (i.e. --2 is not allowed if - is prefix negate).
and indeed, this is biting me, since the language I am trying to parse allows arbitrary repetition of its prefix and postfix operator... | I solved it myself by using chainl1:
prefix p = Prefix . chainl1 p $ return (.)
postfix p = Postfix . chainl1 p $ return (flip (.))
These combinators use chainl1 with an op parser that always succeeds, and simply composes the functions returned by the term parser in left-to-right or right-to-left order. These... | Parsec | 10,475,337 | 17 |
I'm writing my first program with Parsec. I want to parse MySQL schema dumps and would like to come up with a nice way to parse strings representing certain keywords in case-insensitive fashion. Here is some code showing the approach I'm using to parse "CREATE" or "create". Is there a better way to do this? An answer t... | You can build the case-insensitive parser out of character parsers.
-- Match the lowercase or uppercase form of 'c'
caseInsensitiveChar c = char (toLower c) <|> char (toUpper c)
-- Match the string 's', accepting either lowercase or uppercase form of each character
caseInsensitiveString s = try (mapM caseInsensitiveC... | Parsec | 12,937,325 | 17 |
I recently wrote a parser in Python using Ply (it's a python reimplementation of yacc). When I was almost done with the parser I discovered that the grammar I need to parse requires me to do some look up during parsing to inform the lexer. Without doing a look up to inform the lexer I cannot correctly parse the strin... | I believe that pyparsing is based on the same principles as parsec.
| Parsec | 94,952 | 16 |
I'm trying to get this trivial parsec code to compile
import Text.Parsec
simple = letter
but I keep getting this error
No instance for (Stream s0 m0 Char)
arising from a use of `letter'
Possible fix: add an instance declaration for (Stream s0 m0 Char)
In the expression: letter
In an equation for `simple': simple = l... | I think you have ran against the monomorphism restriction. This restriction means: If a variable is declared with no explicit arguments, its type has to be monomorphic. This forces the typechecker to pick a particular instance of Stream, but it can't decide.
There are two ways to fight it:
Give simple an explicit sign... | Parsec | 6,723,208 | 16 |
One common problem I have with Parsec is that it tends to ignore invalid input if it occurs in the "right" place.
As a concrete example, suppose we have integer :: Parser Int, and I write
expression = sepBy integer (char '+')
(Ignore whitespace issues for a moment.)
This correctly parses something like "123+456+789". ... | It's actually pretty simple--just ensure it's followed by eof:
parse (expression <* eof) "<interactive>" "123+456-789"
eof matches the end of the input, even if the input is just a string and not a file.
Obviously, this only makes sense at the top level of your parser.
| Parsec | 16,209,278 | 16 |
I'm looking for a good ocaml parsing library that isn't a derivative of flex/bison. Ideally, I'd like a monadic combinator library along the lines of parsec, but I can't find anything.
I would use haskell, but making llvm bindings for haskell is proving more tiresome than I originally thought.
Cheers,
Duane
| Here's one library, via Google. (Which also brought up this and this, which lists several more relevant-sounding libraries.)
When I wrote a combinator parser in ML, it turned out rather cumbersome to use because of the value restriction and eager evaluation, which forced you to eta-expand your grammar rules. Ocaml is s... | Parsec | 307,499 | 14 |
I'm trying to parse an indentation-based language (think Python, Haskell itself, Boo, YAML) in Haskell using Parsec. I've seen the IndentParser library, and it looks like it's the perfect match, but what I can't figure out is how to make my TokenParser into an indentation parser. Here's the code I have so far:
import q... | It looks like you're using Parsec 3 here, while IndentParser expects Parsec 2. Your example compiles for me with -package parsec-2.1.0.1.
So IndentParser isn't necessarily broken, but the author(s) should have been more specific about versions in the list of dependencies. It's possible to have both versions of Parsec i... | Parsec | 3,023,439 | 14 |
I was trying to use ghc-7.10 (RC 2) and got this message in a number of cases, e.g.,
src/Text/Regex/XMLSchema/Generic/RegexParser.hs:439:5:
Non type-variable argument
in the constraint: Text.Parsec.Prim.Stream s m Char
(Use FlexibleContexts to permit this)
When checking that ‘prop’ has the inferred ty... | This was a change introduced in GHC 7.10.1-rc1:
GHC now checks that all the language extensions required for the inferred type signatures are explicitly enabled. This means that if any of the type signatures inferred in your program requires some language extension you will need to enable it. The motivation is that ad... | Parsec | 28,287,329 | 14 |
All of the parsers in Text.Parsec.Token politely use lexeme to eat whitespace after a token. Unfortunately for me, whitespace includes new lines, which I want to use as expression terminators. Is there a way to convince lexeme to leave a new line?
| No, it is not. Here is the relevant code.
From Text.Parsec.Token:
lexeme p
= do{ x <- p; whiteSpace; return x }
--whiteSpace
whiteSpace
| noLine && noMulti = skipMany (simpleSpace <?> "")
| noLine = skipMany (simpleSpace <|> multiLineComment <?> "")
| noMulti = skipMany (simp... | Parsec | 5,672,142 | 13 |
I'm looking at this library, which has little documentation:
https://pythonhosted.org/parsec/#examples
I understand there are alternatives, but I'd like to use this library.
I have the following string I'd like to parse:
mystr = """
<kv>
key1: "string"
key2: 1.00005
key3: [1,2,3]
</kv>
<csv>
date,windspeed,direct... | I encourage you to define your own parser using those combinators, rather than construct the Parser directly.
If you want to construct a Parser by wrapping a function, as the documentation states, the fn should accept two arguments, the first is the text and the second is the current position. And fn should return a Va... | Parsec | 57,368,870 | 13 |
I've been considering using Haskell's Parsec parsing library to parse a subset of Java as a recursive descent parser as an alternative to more traditional parser-generator solutions like Happy. Parsec seems very easy to use, and parse speed is definitely not a factor for me. I'm wondering, though, if it's possible to i... | One way you can do this is to use the try combinator, which allows a parser to consume input and fail without failing the whole parse.
Another is to use Text.ParserCombinators.ReadP, which implements a symmetric choice operator, in which it is proven that a +++ b = b +++ a, so it really doesn't matter which order. I'm... | Parsec | 2,483,411 | 12 |
I'm surprised that I could not find any info on this. I must be the only person having any trouble with it.
So, let's say I have a dash counter. I want it to count the number of dashes in the string, and return the string. Pretend I gave an example that won't work using parsec's state handling. So this should work:... | You've actually got multiple problems going on here, all of which are relatively non-obvious the first time around.
Starting with the simplest: dash is returning (), which doesn't seem to be what you want given that you're collecting the results. You probably wanted something like dash = char '-' <* modify (+1). (Note ... | Parsec | 6,876,718 | 12 |
Mixing the lexer and parsing phases in one phase sometimes makes Parsec parsers less readable but also slows them down. One solution is to use Alex as a tokenizer and then Parsec as a parser of the token stream.
This is fine but it would be even better if I could get rid of Alex because it adds one preprocessing phase ... | Yes - http://www.cse.unsw.edu.au/~chak/papers/Cha99.html
Before Hackage, Manuel used to release the code in a package called CTK (compiler toolkit). I'm not sure what the status of project is these days.
I think Thomas Hallgren's lexer from the paper "Lexing Haskell in Haskell" was dynamic rather than a code generator... | Parsec | 7,751,647 | 12 |
I am trying to learn how to use Parsec to write a Delphi parser, but I am getting stuck at defining the LanguageDef.
In Delphi, there are two types of comment blocks, (* comments *) and { comments }.
But the types of commentStart & commentEnd of LanguageDef are String, not [String], so I could only put in one or the ot... | My reading of the Text.ParserCombinators.Parsec.Language file is that this cannot be done directly using a LanguageDef.
I believe you are on the right track to write your own whiteSpace parser. In order to use it successfully, you need to overwrite the whiteSpace parser that is generated by makeTokenParser. The Token... | Parsec | 8,384,292 | 12 |
I am looking for some sample grammars written in FParsec that would go beyond the samples in the project repository.
I have found this very nice grammar of GLSL, but this is the only sample I found. What I need is a grammar for a language similar to C or JavaScript.
| Luca Bolognese has written a great series of Write Yourself a Scheme in 48 Hours in F# where he used FParsec for parsing. The full source code with detailed test cases are online here.
The most relevant post is 6th one where he talked about parsing a simple Lisp-like language. This language is closer to JavaScript tha... | Parsec | 9,061,862 | 12 |
I'm new to Haskell and I am trying to parse expressions. I found out about Parsec and I also found some articles but I don't seem to understand what I have to do. My problem is that I want to give an expression like "x^2+2*x+3" and the result to be a function that takes an argument x and returns a value. I am very sorr... | This is just a parser for expressions with variables. Actually interpreting the expression is an entirely separate matter.
You should create a function that takes an already parsed expression and values for variables, and returns the result of evaluating the expression. Pseudocode:
evaluate :: Expr -> Map String Int ->... | Parsec | 4,711,893 | 11 |
I've decided to check out FParsec, and tried to write a parser for λ expressions. As it turns out, eagerness makes recursive parsing difficult. How can I solve this?
Code:
open FParsec
type λExpr =
| Variable of char
| Application of λExpr * λExpr
| Lambda of char * λExpr
let rec FV = function
| Varia... | As you pointed out, the problem is that your parser for application calls expr recursively and so there is an infinite loop. The parser needs to be written such that it always consumes some input and then decides what to do.
In case of lambda calculus, the tricky thing is recognizing an application and a variable becau... | Parsec | 6,186,230 | 11 |
I'm trying to parse some Text with parsec:
data Cmd = LoginCmd String
| JoinCmd String
| LeaveCmd String
deriving (Show)
singleparam :: Parser Cmd
singleparam = do
cmd <- choice [string "leave", string "login", string "join"]
spaces
nick <- many1 anyChar
eof
return $ LoginCmd ... | Parsec does not automatically backtrack like this (for efficiency). The rule is that once a branch accepts a token then alternative branches are pruned. The solution is to add an explicit backtracking using try (string "leave") and try (string "login") etc.
In your example the 'l' character is the token that commits ... | Parsec | 9,976,388 | 11 |
I'm having trouble working out how to use any of the functions in the Text.Parsec.Indent module provided by the indents package for Haskell, which is a sort of add-on for Parsec.
What do all these functions do? How are they to be used?
I can understand the brief Haddock description of withBlock, and I've found examples... | So, the first hint is to take a look at IndentParser
type IndentParser s u a = ParsecT s u (State SourcePos) a
I.e. it's a ParsecT keeping an extra close watch on SourcePos, an abstract container which can be used to access, among other things, the current column number. So, it's probably storing the current "level of... | Parsec | 15,549,050 | 11 |
What does the constraint (Stream s Identity t) mean in the following type declaration?
parse :: (Stream s Identity t)
=> Parsec s () a -> SourceName -> s -> Either ParseError a
What is Stream in the following class declaration, what does it mean. I'm totally lost.
class Monad m => Stream s m t | s -> t where
When I... |
the constraint: (Stream s Identity t) means what?
It means that the input s your parser works on (i.e. [Char]) must be an instance of the Stream class. In the documentation you see that [Char] is indeed an instance of Stream, since any list is.
The parameter t is the token type, which is normally Char and is determin... | Parsec | 6,370,094 | 10 |
In my work I come across a lot of gnarly sql, and I had the bright idea of writing a program to parse the sql and print it out neatly. I made most of it pretty quickly, but I ran into a problem that I don't know how to solve.
So let's pretend the sql is "select foo from bar where 1". My thought was that there is alwa... | Yeah, between might not work for what you're looking for. Of course, for your use case, I'd follow hammar's suggestion and grab an off-the-shelf SQL parser. (personal opinion: or, try not to use SQL unless you really have to; the idea to use strings for database queries was imho a historical mistake).
Note: I add an op... | Parsec | 6,732,272 | 10 |
Is it possible somehow to get parse error of some custom type? It would be cool to get more information about parsing context from error for example. And it seems not very convenient to have error info just in the form of text message.
| As Rhymoid observes, it is not possible directly, unfortunately.
Combining Parsec with your own Either-like monad won't help, too — it will exit too soon (ParsecT over Either) or too late (EitherT over ParsecT).
If you want it badly, you can do it like this: use ParsecT over State (SourcePos, YourErrorType). (You can't... | Parsec | 16,595,565 | 10 |
I was reading a lot about Haskell Parser Combinators and found a lot of topics like:
Parsec vs Yacc/Bison/Antlr: Why and when to use Parsec?
Which Haskell parsing technology is most pleasant to use, and why?
Parsec or happy (with alex) or uu-parsinglib
Choosing a Haskell parser
What is the advantage of using a parser ... | I would say definitely go with Parsec, heres why:
Attoparsec is designed to be quick to use, but lacks the strong support for error messages you get in Parsec, so that is a win for your first point.
My experience of using parser combinator libraries is that it is really easy to test individual parts of the parsers, e... | Parsec | 18,028,220 | 10 |
I was expecting to find a function
integer :: Stream s m Char => ParsecT s u m Integer
or maybe even
natural :: Stream s m Char => ParsecT s u m Integer
in the standard libraries, but I did not find one.
What is the standard way of parsing plain natural numbers directly to an Integer?
| Here is what I often do is to use the expression
read <$> many1 digit
which can have type Stream s m Char => ParsecT s u m Integer (or simply Parser Integer).
I don’t like the use of the the partial function read, but when the parser succeeds I know that the read will succeed, and it is somewhat readable.
| Parsec | 24,171,005 | 10 |
I am trying to parse a very simple language that consists of only decimal or binary numbers. For example, here are some valid inputs:
#b1
#d1
#b0101
#d1234
I am having a problem using Parsec's choice operator: <|>. According to the tutorial: Write yourself a Scheme in 48 hours:
[The choice operator] tries the first p... | Parsec has two kinds of "failure": there are failures that consume input, and failures that don't. To avoid backtracking (and therefore holding onto inputs longer than necessary/being generally unfriendly to the garbage collector), (<|>) commits to the first parser as soon as it consumes input; so that if its first arg... | Parsec | 33,057,481 | 10 |
I'm writing a programming language which uses Parsec for its parsing. For reporting error messages, I've got each element of my syntax tree labelled with its source location, using the getPosition function from the Pos module of Parsec.
However, it only gives the location of the beginning of each expression I parse, a... | You can use getPosition after you parse as well.
import Text.Parsec
import Text.Parsec.String
spanned :: Parser a -> Parser (SourcePos, SourcePos, a)
spanned p = do
pos1 <- getPosition
a <- p
pos2 <- getPosition
pure (pos1, pos2, a)
Testing:
> parseTest (spanned (many1 (char 'a'))) "aaaaafff"
((line 1, column... | Parsec | 36,078,405 | 10 |
I was wondering, if there is a standard, canonical way in Haskell to write not only a parser for a specific file format, but also a writer.
In my case, I need to parse a data file for analysis. However, I also simulate data to be analyzed and save it in the same file format. I could now write a parser using Parsec or s... | The BNFC-meta package https://hackage.haskell.org/package/BNFC-meta-0.4.0.3
might be what you looking for
"Specifically, given a quasi-quoted LBNF grammar (as used by the BNF Converter) it generates (using Template Haskell) a LALR parser and pretty pretty printer for the language."
update: found this package that also ... | Parsec | 45,239,430 | 10 |
We are trying to evaluate Keycloak as an SSO solution, and it looks good in many respects, but the documentation is painfully lacking in the basics.
For a given Keycloak installation on http://localhost:8080/ for realm test, what are the OAuth2 Authorization Endpoint, OAuth2 Token Endpoint and OpenID Connect UserInfo E... | For Keycloak 1.9 and above, the above information can be retrieved via the url
http://keycloakhost:keycloakport/realms/{realm}/.well-known/openid-configuration
For example, if the realm name is demo:
http://keycloakhost:keycloakport/realms/demo/.well-known/openid-configuration
An example output from above url:
{
... | Keycloak | 28,658,735 | 210 |
I want to create a fairly simple role-based access control system using Keycloak's authorization system. The system Keycloak is replacing allows us to create a "user", who is a member of one or more "groups". In this legacy system, a user is given "permission" to access each of about 250 "capabilities" either through g... | Full transparency—I am by no means a Keycloak, OAuth, or OIDC expert and what I know is mostly from reading the docs, books, good ol' YouTube and playing around with the tool.
This post will be comprised of two parts:
I'll attempt to answer all your questions to the best of my ability
I'll show you all how you can pla... | Keycloak | 42,186,537 | 210 |
Does keycloak client id has a client secret? I tried to create a client in keycloak admin but I was not able to spot client secret.
Is it auto generated? Where can I get the secret?
| Your client need to have the access-type set to confidential , then you will have a new tab credentials where you will see the client secret.
https://wjw465150.gitbooks.io/keycloak-documentation/content/server_admin/topics/clients/oidc/confidential.html
| Keycloak | 44,752,273 | 140 |
Keycloak refresh token lifetime is 1800 seconds:
"refresh_expires_in": 1800
How to specify different expiration time? In Keycloak admin UI, only access token lifespan can be specified:
| As pointed out in the comments by @Kuba Šimonovský the accepted answer is missing other important factors:
Actually, it is much much much more complicated.
TL;DR One can infer that the refresh token lifespan will be equal to the smallest value among (SSO Session Idle, Client Session Idle, SSO Session Max, and Client ... | Keycloak | 52,040,265 | 99 |
I need to make the user keep login in the system if the user's access_token get expired and user want to keep login. How can I get newly updated access_token with the use of refresh_token on Keycloak?
I am using vertx-auth for the auth implementation with Keycloak on vert.x. Is it possible to refresh access_token with ... | keycloak has REST API for creating an access_token using refresh_token. It is a POST endpoint with application/x-www-form-urlencoded
Here is how it looks:
Method: POST
URL: https://keycloak.example.com/auth/realms/myrealm/protocol/openid-connect/token
Body type: x-www-form-urlencoded
Form fields:
client_id : <my-c... | Keycloak | 51,386,337 | 77 |
I have keycloak standalone running on my local machine.
I created new realm called 'spring-test', then new client called 'login-app'
According to the rest documentation:
POST: http://localhost:8080/auth/realms/spring-test/protocol/openid-connect/token
{
"client_id": "login-app",
"username": "user123",
"pas... | You should send your data in a POST request with Content-Type header value set to application/x-www-form-urlencoded, not json.
| Keycloak | 53,795,179 | 74 |
I have issue while calling Keycloak's logout endpoint from an (mobile) application.
This scenario is supported as stated in its documentation:
/realms/{realm-name}/protocol/openid-connect/logout
The logout endpoint logs out the authenticated user.
The user agent can be redirected to the endpoint, in which case the... | Finally, I've found the solution by looking at the Keycloak's source code: https://github.com/keycloak/keycloak/blob/9cbc335b68718443704854b1e758f8335b06c242/services/src/main/java/org/keycloak/protocol/oidc/endpoints/LogoutEndpoint.java#L169. It says:
If the client is a public client, then you must include a "client_... | Keycloak | 46,689,034 | 66 |
In my rest service i can obtain the principal information after authentication using
KeycloakPrincipal kcPrincipal = (KeycloakPrincipal) servletRequest.getUserPrincipal();
statement.
Keycloak principal doesn't contain all the information i need about the authenticated user.
Is it possible to customize my own principal... | To add custom attributes you need to do three things:
Add attributes to admin console
Add claim mapping
Access claims
The first one is explained pretty good here: https://www.keycloak.org/docs/latest/server_admin/index.html#user-attributes
Add claim mapping:
Open the admin console of your realm.
Go to Clients and op... | Keycloak | 32,678,883 | 54 |
so I have a problem getting keycloak 3.2.1 to work behind kong (0.10.3), a reverse proxy based on nginx.
Scenario is:
I call keycloak via my gateway-route via https://{gateway}/auth and it shows me the entrypoint with keycloak logo, link to admin console etc. - so far so good.
But when clicking on administration cons... | This sounds somehow like a duplicate of Keycloak Docker behind loadbalancer with https fails
Set the request headers X-Forwarded-For and X-Forwarded-Proto in nginx. Then you have to configure Keycloak (Wildfly, Undertow) to work together with the SSL terminating reverse proxy (aka load balancer). See http://www.keycloa... | Keycloak | 47,181,821 | 54 |
Keycloak is a great tool, but it lacks proper documentation.
So we have Realm.roles, Client.roles and User.roles
How do there 3 work together when accessing an application using a specific client?
Sincerely,
| In KeyCloak we have those 3 roles:
Realm Role
Client Role
Composite Role
There are no User Roles in KeyCloak. You most likely confused that with User Role Mapping, which is basically mapping a role (realm, client, or composite) to the specific user
In order to find out how these roles actually work, let's first take ... | Keycloak | 47,837,613 | 52 |
I have a client in keycloak for my awx(ansible tower) webpage.
I need only the users from one specific keycloak group to be able to log in through this client.
How can I forbid all other users(except from one particular group) from using this keycloak client?
| I found a solution which does not require the scripts extension or any changes on the flow.
The key for this solution are the Client Scopes. An application which wants to to authorize a user needs a scope like email or uid, right? What if you only pass them to an application if a user is in a specific group?
In the fol... | Keycloak | 54,305,880 | 52 |
What is the correct way to set the aud claim to avoid the error below?
unable to verify the id token {"error": "oidc: JWT claims invalid: invalid claims, 'aud' claim and 'client_id' do not match, aud=account, client_id=webapp"}
I kinda worked around this error message by hardcoding aud claim to be the same as my cli... | With recent keycloak version 4.6.0 the client id is apparently no longer automatically added to the audience field 'aud' of the access token.
Therefore even though the login succeeds the client rejects the user.
To fix this you need to configure the audience for your clients (compare doc [2]).
Configure audience in K... | Keycloak | 53,550,321 | 50 |
There is an Endpoint to a backend server which gives a JSON response on pinging and is protected by an Apigee Edge Proxy. Currently, this endpoint has no security and we want to implement Bearer only token authentication for all the clients making the request.
All the clients making the requests to API will send that ... | This got figured out with the help of this medium article. All the steps I have mentioned below have a detailed description in the article (Refer step 1 to 9 for token part, other steps are related to Spring Boot application) but I would like to give a overview of those in reference to my question.
Generating a JWT tok... | Keycloak | 54,884,938 | 49 |
I am calling /auth/realms/master/protocol/openid-connect/token to get access token by sending below content in body,
grant_type=password&client_id=example-docker-jaxrs-app&username=user&password=password&client_secret=1d27aedd-11c2-4ed2-97d5-c586e1f9b3cd
but when I put update password as required action to user from ke... | If you mark the password as temporary a user action to update password is marked as required.
And until the password has been updated/set by the user i.e. this action has been completed, you won't be able to get an access token using this user since the account is not "fully setup" and is in a kind of intermediate sta... | Keycloak | 42,524,153 | 48 |
I'm using the Keycloak authorization server in order to manage my application permissions. However, I've found out the standalone server can be accessed locally only.
http://localhost:8080/auth works, but not it does http://myhostname:8080/auth. This issue doesn't permit accessing the server from the internal network.
| The standalone Keycloak server runs on the top of a JBoss Wildfly instance and this server doesn't allow accessing it externally by default, for security reasons (it should be only for the administration console, but seems to affect every url in case of Keycloak). It has to be booted with the -b=0.0.0.0 option to enabl... | Keycloak | 34,410,707 | 46 |
I Have integrated keycloak with an angular app. Basically, both frontend and backend are on different server.Backend app is running on apache tomcat 8. Frontend app is running on JBoss welcome content folder.
Angular config
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak... | I was fighting with KeyCloak and CORS and all of this for about two weeks, and this is my solution (for keycloak 3.2.1):
Its all about configuring KeyCloak server.
It seems to be, that WebOrigin of your Realm needs to be *
Only one origin "*".
Thats all, what was needed for me.
If you enter your server as WebOrigin, th... | Keycloak | 45,051,923 | 46 |
How can I set the docker keycloak base url as parameter ?
I have the following nginx reverse proxy configuration:
server {
listen 80;
server_name example.com;
location /keycloak {
proxy_pass http://example.com:8087/;
}
}
When I try to access http://example.com/keycloak/ I got a keycloak http r... | Just tested that @home, and actually multiple configuration additions are needed:
1/ Run the keycloak container with env -e PROXY_ADDRESS_FORWARDING=true as explained in the docs, this is required in a proxy way of accessing to keycloak:
docker run -it --rm -p 8087:8080 --name keycloak -e PROXY_ADDRESS_FORWARDING=true ... | Keycloak | 44,624,844 | 44 |
I want to secure my Spring Boot 2.1 app with Keycloak 4.5.
Currently I cannot start the application due to the following error:
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.support.BeanDefinitionOverrideException:
Invalid bean definition with na... | This helped me to resolve an issue, remove @KeycloakConfiguration and use this instead (from KEYCLOAK-8725):
Java:
@Configuration
@ComponentScan(
basePackageClasses = KeycloakSecurityComponents.class,
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.keycloak.adapters.spring... | Keycloak | 53,318,134 | 42 |
I am going to secure my golang application using keycloak, but keycloak itself does not support go language.
There are some go adaptor as an open project in github that has implemented openId connect protocol as a provider service, but they do not provide an example or documentation on how to integrate libraries with ... | As you have pointed out, there is no official keycloak adapter for golang.
But it is pretty straight forward to implement it. Here is a little walk through.
Keycloak server
For this example, I will use the official keycloak docker image to start the server.
The version used is 4.1.0.Final. I think this will work with o... | Keycloak | 48,855,122 | 35 |
I am trying to get the REST API of keycloak to work.
Thanks to this post I was able to get the token. But when trying the example for the list of users in the first answer, I get the error:
"error": "RESTEASY003210: Could not find resource for full path: http://PATHTOCEAKLOAK:81/auth/user/realms/master/users"
Here my ... | For those who are still facing this error and using 17.0+ version of Keycloak, there's a change in endpoints as per the official documentation. I resolved this issue by just using {realm}/user and omitting /auth in between.
| Keycloak | 70,577,004 | 35 |
I updated to Spring Boot 3 in a project that uses the Keycloak Spring Adapter. Unfortunately, it doesn't start because the KeycloakWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter which was first deprecated in Spring Security and then removed. Is there currently another way to implement security with ... | You can't use Keycloak adapters with spring-boot 3 for the reason you found, plus a few others related to transitive dependencies. As most Keycloak adapters were deprecated in early 2022, it is very likely that no update will be published to fix that.
Instead, use spring-security 6 libs for OAuth2. Don't panic, it's an... | Keycloak | 74,571,191 | 33 |
I'm trying to copy an entire directory from my docker image to my local machine.
The image is a keycloak image, and I'd like to copy the themes folder so I can work on a custom theme.
I am running the following command -
docker cp 143v73628670f:keycloak/themes ~/Development/Code/Git/keycloak-recognition-login-branding
... | EDIT
As a result of running 'pwd' your should run the Docker cp command as follows:
docker cp 143v73628670f:/opt/jboss/keycloak/themes ~/Development/Code/Git/keycloak-recognition-login-branding
You are forgetting the trailing ' / '. Therefore your command should look like this:
docker cp 143v73628670f:/keycloak/themes... | Keycloak | 46,729,330 | 32 |
We are using keycloak-adapter with Jetty for authentication and authorization using Keycloak.
As per Keycloak doc for OIDC Auth flow:
Another important aspect of this flow is the concept of a public vs. a confidential client. Confidential clients are required to
provide a client secret when they exchange the tempo... | As far as I understood, you have your frontend and backend applications separated. If your frontend is a static web-app and not being served by the same backend application (server), and your backend is a simple REST API - then you would have two Keycloak clients configured:
public client for the frontend app. It woul... | Keycloak | 53,118,828 | 31 |
I have installed keycloack server 4.3.4.
How to activate the REST API of keycloak (Add a user, enabled user, disabled a user ...) ?
Regards
| First step to do that is create an admin account (which you would have been prompted to do as soon as you would have opened {keycloak-url}/auth ).
Next steps depend on how you want to create config. Through Admin console GUI or through Rest API.
Steps to do this through Admin Rest API.
First , you will have to get a t... | Keycloak | 53,283,281 | 31 |
I have a user base with identity and authentication managed by keycloak. I would like to allow these users to login and use AWS API Gateway services with Cognito using an OpenID Connect federation.
The AWS documentation on using an OpenID Connect provider is somewhat lacking. I found an old reference using SAML but wou... | Answering my own question for future searchers based on advice I have received from AWS Support:
The question itself was based on a misunderstanding. AWS Cognito does not authenticate users with Keycloak - the client application does that.
Cognito Identity Federation is about granting access to AWS resources by creatin... | Keycloak | 49,810,326 | 30 |
I am recently working on Keycloak 6.0.1 for SSO for authentication for multiple applications in organisation. I am confused in difference between clients and realm.
If I have 5 different application to be managed for SSO then do I have to create 5 different clients or 5 different realm ?
If I say I have to create 5 ... | According to Keycloak documentation
Realm - A realm manages a set of users, credentials, roles, and groups. A user belongs to and logs into a realm. Realms are isolated from one another and can only manage and authenticate the users that they control.
Clients are entities that can request Keycloak to authenticate a u... | Keycloak | 56,561,554 | 30 |
Is there any existing Keycloak client for Asp.net Core? I have found a NuGet package for .net but it doesn't work with Core. Do you have any ideas how to easily integrate with this security server (or maybe using any other alternatives)?
| I've played a bit with this today. The most straightforward way is too use OpenId standard.
In Startup.cs I used OpenIdConnect Authentication:
public void Configure(...)
{ (...)
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationScheme = CookieAuthentication... | Keycloak | 41,721,032 | 29 |
I know that there is admin APIs to get the list of users which returns the user representation array.
GET /admin/realms/{realm}/groups/{id}/members
returns
https://www.keycloak.org/docs-api/2.5/rest-api/index.html#_userrepresentation
but is there a way to get users by custom attribute ?
| This is enabled out of the box from Keycloak version 15.1.0
Using GET /{realm}/users API, parameter q is introduced: A query to search for custom attributes, in the format 'key1:value2 key2:value2'
curl 'http://{{keycloak_url}}/auth/admin/realms/{{realm}}/users?q=phone:123456789'
You can also combine several attribut... | Keycloak | 54,667,407 | 29 |
The deployment is on AWS and I do not want to tunnel to the box and open a browser to disable it.
There seems to exist a configuration: "ssl-required":"none" that can be placed in the keycloak-server.json file, but I'm not sure under which object. I've tried under "realm" and by itself with no luck.
I do not want ... | In the "master" realm, over login tab. Change 'Require SSL' property to none.
If you can not access locally to keycloak and it is configured with a database for instance Postgres, then execute the following SQL sentence.
update REALM set ssl_required = 'NONE' where id = 'master';
It is necessary to restart keycloak
| Keycloak | 38,337,895 | 28 |
Is there a way to get a list of users on a Keycloak realm via REST WITHOUT using an admin account? Maybe some sort of assignable role from the admin console? Looking for any ideas.
Right now I'm using admin credentials to grab an access token, then using that token to pull users from the realm/users endpoint.
Getting t... | You need to assign the view-users role from the realm-management client, for the desired user. That would be the configuration for the user:
Then you can grab all the users from the ${keycloakUri}/admin/realms/${keycloakRealm}/users endpoint. That's the info retrieved from the enpoint, accesed via Postman:
Also, unre... | Keycloak | 46,470,477 | 28 |
Running keycloak on standalone mode.and created a micro-service by using node.js adapter for authenticating api calls.
jwt token from the keyclaok is sending along with each api calls. it will only respond if the token sent is a valid one.
how can i validate the access token from the micro service?
is there any token ... | To expand on troger19's answer:
Question 1: How can I validate the access token from the micro service?
Implement a function to inspect each request for a bearer token and send that token off for validation by your keycloak server at the userinfo endpoint before it is passed to your api's route handlers.
You can find... | Keycloak | 48,274,251 | 28 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.