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 know there are thousands of questsions like this one here on SO but i've seen them all and i'm still not able to deal with my problem. I'm doing everything using ansible so it's quite automated but, anyway, here are my files: pg_hba.conf local all all trust host al...
psql is using a local socket connection, rails is using localhost over TCP/IP. Local is trusted, localhost requires a password (using md5). You could setup a pgpass file for your rails user: http://www.postgresql.org/docs/current/static/libpq-pgpass.html
Ansible
27,419,961
22
When I use lineinfile in ansible it is not writing ', " characters lineinfile: 'dest=/home/xyz state=present line="CACHES="default""' it is giving CACHES=default but the desired output is CACHES="default" How to achieve this?
it appears you can escape the quotes: - lineinfile: dest=/tmp/xyz state=present line="CACHES=\"default\"" That gives this output: $ cat /tmp/xyz CACHES="default" You don't need to escape single quotes that are inside double quotes: - lineinfile: dest=/tmp/xyz state=present line="CACHES=\"default\" foo='x'" cat /tmp/x...
Ansible
24,126,943
22
We have one Ansible role that needs to run three tasks in the handlers/main.yml task file, but it only runs the first task. How do I force it to run the other two tasks? I do have the ignore flag on for if the first task fails. The tasks/main.yml file looks like: - name: openfire | Copy plugins into openfire/plugins ...
Its possible for handler to call another notify. Multiple notify calls are also allowed: --- - name: restart something command: shutdown.sh notify: - wait for stop - start something - wait for start - name: wait for stop wait_for: port={{port}} state=stopped - name: start something command: start...
Ansible
21,389,364
22
I'm converting a vagrant provisioner from shell to ansible and I was wondering if there's any option to show the actual time it takes to complete each task? Ideally I want to benchmark the difference between installing multiple packages in yum using a shell: method and the in built yum: with_items method. ATM I'm sitt...
I've solved for timing Ansible task durations by adding a callback plugin. Callback plugins were designed to allow you to run your own arbitrary code based on events that happen in the context of an Ansible run. The plugin I use is easily deployed by creating a callback_plugins directory and dropping a python script in...
Ansible
19,857,343
22
The documentation refers us to the github example, but this is a bit sparse and mysterious. It says this: # created with: # crypt.crypt('This is my Password', '$1$SomeSalt') password: $1$SomeSalt$UqddPX3r4kH3UL5jq5/ZI. but crypt.crypt doesn't emit what the example shows. It also uses MD5. I tried this: # python impor...
The python example shown in the documentation depends on what version of crypt is running on the OS you are using. I generated the crypt on OS X and the server I was targetting is ubuntu. Due to differences in which implementation of crypt is offered by the OS, the result is different and incompatible. Use this inst...
Ansible
15,231,661
22
I have noticed that terraform will only run "file", "remote-exec" or "local-exec" on resources once. Once a resource is provisioned if the commands in a "remote-exec" are changed or a file from the provisioner "file" is changed then terraform will not make any changes to the instance. So how to I get terraform to run...
Came across this thread in my searches and eventually found a solution: resource "null_resource" "ansible" { triggers { key = "${uuid()}" } provisioner "local-exec" { command = "ansible-playbook -i /usr/local/bin/terraform-inventory -u ubuntu playbook.yml --private-key=/home/user/.ssh/aws_user.pem -u ubu...
Ansible
39,069,311
21
I am running the following ansible playbook - hosts: localhost connection: local vars_files: - vars/config_values.yaml gather_facts: no tasks: - name: Set correct project in gcloud config shell: "gcloud config set project {{ google_project_name }}" Which yields the following warning: [WARNING]...
These are just warnings telling you that: you did not provide any inventory file either with the -i option, in your ansible.cfg or by default in /etc/ansible/hosts (and hence none was parsed and it is empty) your inventory is empty and hence only the implicit localhost is available (reminding you that it does not matc...
Ansible
59,938,088
21
I’m seeing the above message on multiple playbooks using Ansible 2.8 on Ubuntu 18.04. In the interests of simplicity I’ve reproduced it using this basic playbook for a single node Drupal server. https://github.com/geerlingguy/ansible-for-devops/tree/master/drupal; this playbook works fine on earlier versions of ubuntu,...
Your remote host is telling you: The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required. Did you follow the recommendations and install the required pymysql python package on your remote host ? For a quick test, on your remote host: if using python 2.7: sudo pip install pymysql if u...
Ansible
56,313,083
21
With Ansible please advise how i could download the latest release binary from Github repository. As per my current understanding the steps would be: a. get URL of latest release b. download the release For a. I have something like which does not provide the actual release (ex. v0.11.53): - name: get latest Gogs relea...
Github has an API to manipulate the release which is documented. so imagine you want to get the latest release of ansible (which belong to the project ansible) you would call the url https://api.github.com/repos/ansible/ansible/releases/latest get an json structure like this { "url": "https://api.github.com/repos/...
Ansible
50,966,777
21
I'm trying multiple concatenation when preforming with_items for the destination section. Right now it looks like this: - name: create app except+lookup copy: content="" dest="{{ dir.comp ~ '/config/con2dd/' ~ item.name ~ 'File.txt' }}" force=no group=devops owner=devops mode: 0755 with_items: ... I get: We could ...
Don't mix pure YAML and key=value syntaxes for parameters. And always use YAML syntax for complex arguments: - name: create app except+lookup copy: content: "" dest: "{{ dir.comp }}/config/con2dd/{{ item.name }}File.txt" force: no group: devops owner: devops mode: 0755 with_items: ...
Ansible
45,400,851
21
I am trying to download and extract a tar archive in the remote machine and remote destination must be created if not exists. BUT it is not happening. ERROR: destination directory doesn't exist MYCODE: - unarchive: src: http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.15/bin/apache-tomcat-8.5.15.tar.gz ...
While using the unarchive module, the dest path should be a path to an existing directory, and creates should be a path to a file and not a boolean. - name: ensure tomcat directory exists file: path: /opt/tomcat state: directory - unarchive: src: http://apache.mirrors.ionfish.org/tomcat/tomcat-8/v8.5.15...
Ansible
44,719,303
21
When I run this on the command line it works fine: echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb But in Ansible it does not want to run in shell: - name: partition new disk shell: echo -e "n\np\n1\n\n\nw" | sudo fdisk /dev/sdb It does not come back with an error, but it does not create the partition either. I c...
With Ansible 2.3 and above, you can use parted module to create partitions from a block device. For example: - parted: device: /dev/sdb number: 1 flags: [ lvm ] state: present To format the partition just use filesystem module as shown below: - filesystem: fstype: ext2 dev: /dev/sdb1 T...
Ansible
42,348,098
21
I am trying to install node js version using nvm using below Ansible yml file. I get error like source "source /home/centos/.nvm/nvm.sh" file not found. But if I do the same by logging into the machine using ssh then it works fine. - name: Install nvm git: repo=https://github.com/creationix/nvm.git dest=~/.nvm versio...
Regarding the "no such file" error: source is an internal shell command (see for example Bash Builtin Commands), not an external program which you can run. There is no executable named source in your system and that's why you get No such file or directory error. Instead of the command module use shell which will execut...
Ansible
41,379,083
21
I'm having trouble running a full playbook because some of the facts later plays depend on are modified in earlier plays, but ansible doesn't update facts mid-run. Running ansible somehost -m setup when the whole playbook starts against a new VPS: "ansible_selinux": { "status": "disabled" }, My playbook contains ...
Add this in your playbook to use the setup module to update the facts. For example I added another interface with DHCP now I want to know what address it has then do this: - name: do facts module to get latest information setup:
Ansible
35,185,635
21
I have a host_var in ansible with dict with all interfaces: --- interfaces: vlan0: ip: 127.0.0.1 mask: 255.255.255.0 state: true vlan2: ip: 127.0.1.1 mask: 255.255.255.0 state: true And I want to check if dict has a key vlan1 if ok put to template value vlan1.ip else put vlan2.ip. {% if in...
The answer is simple and it showed on ansible error message. First of all I need to check if var is defined. {% if interfaces.vlan1 is defined %} {{ interfaces.vlan1.ip }} {% else %} {{ interfaces.vlan2.ip|default("127.0.3.1") }} {% endif %} This combination works well.
Ansible
33,400,771
21
I have a specific ansible variable structure that I want to get from the vault into a yaml file on my hosts. Lets assume a structure like this: secrets: psp1: username: this password: that secret_key: 123 ... I need something like a "generic" template to output whatever "secrets" contains at the mome...
As jwodder said, it's valid. If you're using to_yaml (instead of to_nice_yaml) you have fairly old install of ansible, it's time to upgrade. Use to_nice_yaml It's possible to pass your own kwargs to filter functions, which usually pass them on to underlying python module call. Like this one for your case. So something...
Ansible
28,963,751
21
In Ansible, if I try to use a variable as a parameter name, or a key name, it is never resolved. For example, if I have {{ some_var }}: true, or: template: "{{ resolve_me_to_src }}": "some_src" the variables will just be used literally and never resolve. My specific use case is using this with the ec2 module, where so...
Will this work for you? (rc=0)$ cat training.yml - hosts: localhost tags: so5 gather_facts: False vars: [ k1: 'key1', k2: 'key2', d1: "{ '{{k1}}': 'value1', '{{k2}}': 'value2', }", ] tasks: - debug: msg="{{item}}" with_dict: "{{d1}}" (rc=0)$ ansible-playbook t...
Ansible
27,805,976
21
I would like to know if there is a way to print information while a module is executing -- primarily as a means to demonstrate that the process is working and has not hung. Specifically, I am trying to get feedback during the execution of the cloudformation module. I tried modifying the (Python) source code to include ...
My approach for localhost module: ... module.log(msg='test!!!!!!!!!!!!!!!!!') ... Then on another window: $ tail -f /var/log/messages Nov 29 22:32:44 nfvi-ansible-xxxx python2: ansible-test-module test!!!!!!!!!!!!!!!!!
Ansible
25,918,068
21
I am trying to use multiple inventory file and dynamic inventory with Ansible 1.4 and dev. Ansible returns No hosts matched. I have a simulated scenario with two hosts file in a directory test the content of the directory is listed. hosts1.ini [group1] test1 ansible_ssh_host=127.0.0.1 test2 ansible_ssh_host=127.0...
Remove the .ini from your file names: $ ls test/ hosts1 hosts2 $ ansible -i test --list-hosts all test1 test2 test3 test5 test6 test4
Ansible
21,638,996
21
Example scenario: config files for a certain service are kept under version control on a private github repo. I want to write a playbook that fetches one of these files on the remote node and puts it into the desired location. I can think of several solutions to this: do a checkout on the machine that runs ansible (lo...
I'll start by saying that we chose the 2nd solution for our production environment and I guarantee one thing - it just works. Now for the longer version: Solution no. 1: Simple and robust - will just work Does not "contaminate" production servers with irrelevant files (other configuration files) Does not load producti...
Ansible
21,590,906
21
I have some Terraform code with an aws_instance and a null_resource: resource "aws_instance" "example" { ami = data.aws_ami.server.id instance_type = "t2.medium" key_name = aws_key_pair.deployer.key_name tags = { name = "example" } vpc_security_group_ids = [aws_security_group.main.id] }...
The null_resource is currently only going to wait until the aws_instance resource has completed which in turn only waits until the AWS API returns that it is in the Running state. There's a long gap from there to the instance starting the OS and then being able to accept SSH connections before your local-exec provision...
Ansible
62,403,030
20
How can I run a local command on a Ansible control server, if that control server does not have a SSH daemon running? If I run the following playbook: - name: Test commands hosts: localhost connection: local gather_facts: false tasks: - name: Test local action local_action: command echo "hello world" ...
how to run a specific command from Ansible, without Ansible first trying to SSH to localhost. connection: local is sufficient to make the tasks run in the controller without using SSH. Try, - name: Test commands hosts: localhost connection: local gather_facts: false tasks: - name: Test local action ...
Ansible
61,295,544
20
In my inventory I define hosts like this: [server1] 141.151.176.223 I am looking for a variable which keeps the server1 name, as I am using it to define server hostname. inventory_hostname is set to 141.151.176.223 ansible_hostname as well as inventory_hostname_short is set to 148. To workaround this problem I am se...
Explanation If the inventory file was defined this way: [server1_group] server1 ansible_host=141.151.176.223 Then you can access: server1 with the inventory_hostname fact; 141.151.176.223 with the ansible_host fact; server1_group with group_names|first (group_names fact contains a list of all groups server belongs to...
Ansible
48,367,708
20
I want to change sudo session timeout according to this answer. I can edit ordinary file: lineinfile: path: /etc/sudoers regexp: ^Defaults env_reset line: Defaults env_reset,timestamp_timeout=60 But in first line of my /etc/sudoers written: # This file MUST be edited with the 'visudo' command as root. How to d...
There's a safenet option for such cases: validate. The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the example below. The command is passed securely so shell features like expansion and pipes won't work. If you look at the exa...
Ansible
46,720,411
20
I'm trying to loop a dictionary through an ansible template using jinja2 to create a number of datasources but receive this error [{'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'dict object' has no attribute 'value'", 'failed': True}]} When running a debug task it does get the correct values back ...
I discovered today that using dict.values() loops over each dict element's values rather than its keys. So you should be able use something like this for your template. {% for item in databases.values() %} <resource name="{{ item.db_resource }}" auth="container" type="javax.sql.datasource" maxtotal="{{ item.db_max...
Ansible
37,756,586
20
Using Ansible I'm having a problem registering a variable the way I want. Using the implementation below I will always have to call .stdout on the variable - is there a way I can do better? My playbook: Note the unwanted use of .stdout - I just want to be able to use the variable directly without calling a propery...?...
If I understood it right you want to assign deploy_dir.stdout to a variable that you can use without stdout key. It can be done with set_fact module: tasks: - name: init deploy dir shell: echo ansible-deploy-$(date +%Y%m%d-%H%M%S-%N) # http://docs.ansible.com/ansible/playbooks_variables.html register: dep...
Ansible
37,479,605
20
It seems that getting failures due to /var/lib/dpkg/lock is something not very rare. Based on observations these are caused most of the time 9/10 due to state lock file or while a cron job was running. This means that a retry mechanism combined with a removal of stale file could be the solution. How can I do this in a...
I'd try to solve this with until feature of ansible (http://docs.ansible.com/ansible/latest/playbooks_loops.html#do-until-loops) - name: Apt for sure apt: name=foobar state=installed register: apt_status # 2018 syntax: # until: apt_status|success # 2020 syntax: until: apt_status is success delay: 6 retr...
Ansible
36,630,299
20
Normally, you can ssh into a Vagrant-managed VM with vagrant ssh. There are two options: You can use an insecure_private_key generated by Vagrant to authenticate. Use your own private key - provided that config.ssh.forward_agent is set to true, and the VM is configured correctly I use the second option. S when I ru...
The problem probably lies within your hosts/inventory file. You need to add the proper connection configuration for Ansible therein, save and re-run. 192.168.50.5 ansible_ssh_port=22 ansible_ssh_user=vagrant ansible_ssh_private_key_file=~/.ssh/id_rsa If you are not using port 22, adjust the ansible_ssh_port in your h...
Ansible
32,748,585
20
I am about to bump up the changelog of a lot of locally developed debian packages. I am using 'Ansible' to call 'dch' from the devscripts package. I am using Ansible because I already have the subversion paths to the packages listed in an Ansible variable. I would like to be able to enter the actual changelog message a...
That is because it is processed by shell first which eats the quotes and backslashes you used. You can enclose the whole argument into single quotes which tells shell not to touch what is inside. Then the value of the variable can be enclosed into double quotes, which will remain there for ansible. ansible-playbook tag...
Ansible
32,584,112
20
jinja2 has filter '|default()' to works with undefined variables. But it does not work with dictionary values. if D may have or not have key foo (D[foo]), than: {{ D[foo]|default ('no foo') }} will prints 'no foo' if D is undefined, but will cause error ('dict object' has no attribute 'foo') if D is defined, but D[foo...
This appears to be working properly for me using Ansible 1.7.2. Here's a test playbook I just wrote: --- - hosts: localhost vars: D: 1 : "one" 2 : "two" tasks: - debug: var=D - debug: msg="D[1] is {{ D[1]|default ('undefined') }}" - debug: msg="D[3] is {{ D[3]|default ('undefined'...
Ansible
28,885,184
20
I am trying to write a task which runs a list of ldapmodify statements and only want it to fail if any of the return codes are not 0 or 68 (object allready existed): - name: add needed LDAP infrastructure action: command ldapmodify -x -D '{{ ADMINDN }}' -w '{{ LDAPPW }}' -H {{ LDAPURI }} -c -f {{ item }} register: ...
Well, it turns out I was going about it much too complicated. The problem was: Ansible runs failed_when after every iteration of the loop. As such I simply need to access result.rc: - name: add needed LDAP infrastructure action: command ldapmodify -x -D '{{ ADMINDN }}' -w '{{ LDAPPW }}' -H {{ LDAPURI }} -c -f...
Ansible
25,981,863
20
In my playbook I have - name: Grab h5bp/server-configs-nginx git: repo=https://github.com/h5bp/server-configs-nginx.git dest=/tmp/server-configs-nginx version="3db5d61f81d7229d12b89e0355629249a49ee4ac" force=yes - name: Copy over h5bp configuration command: cp -r /tmp/server-configs-nginx...
You can use the synchronize module with mode='pull' - name: Copy over h5bp configuration synchronize: mode=pull src=/tmp/server-configs-nginx/{{ item }} dest=/etc/nginx/{{ item }} with_items: - "mime.types" - "h5bp/" Note: To copy remote-to-remote, use the same command and add delegate_to (as remote source) a...
Ansible
25,576,871
20
I'm trying to get this task to run locally (on the machine that is running the playbook) : - name: get the local repo's branch name local_action: git branch | awk '/^\*/{print $2}' register: branchName I tried plenty of variations with no success all other tasks are meant to run on the target host, which is why ru...
The format for local_action is: local_action: <module_name> <arguments> In your example, Ansible thinks you are trying to use the git module and throws an error because you don't have the correct arguments for the git module. Here is how it should look: local_action: shell git branch | awk '/^\*/{print $2}' Source: h...
Ansible
25,144,608
20
I have a command in ubuntu as sudo chown $(id -u):$(id -g) $HOME/.kube/config I want to convert into ansible script. I have tried below - name: Changing ownership command: chown $(id -u):$(id -g) $HOME/.kube/config become: true but i am getting error as below fatal: [ubuntu]: FAILED! => {"changed"...
Assuming the file already exists and you just want to change permissions, you can retrieve user ID and group from Ansible facts and do something like: - name: Change kubeconfig file permission file: path: $HOME/.kube/config owner: "{{ ansible_effective_user_id }}" group: "{{ ansible_effective_group_id }}...
Ansible
57,070,583
19
Can I print a warning message from Ansible? Like as Ansible does for an internal warning: [WARNING]: Ignoring invalid attribute: xx The targeted use are warning, that are not an error, so they should not end the playbook execution, but they should be clearly visible (in standard Ansible purple color). Example usage: ...
Here is a simple filter plugin that will emit a Warning message: from ansible.utils.display import Display class FilterModule(object): def filters(self): return {'warn_me': self.warn_filter} def warn_filter(self, message, **kwargs): Display().warning(message) return message Place the above i...
Ansible
48,033,923
19
I want to make the command via Ansible: curl -sL https://deb.nodesource.com/setup | sudo bash - How can I do it via Ansible? Now I have: - name: Add repository command: curl -sL https://deb.nodesource.com/setup | sudo bash - But it throw error: [WARNING]: Consider using get_url or uri module rather than running cur...
You can: - name: Add repository shell: curl -sL https://deb.nodesource.com/setup | sudo bash - args: warn: no shell to allow pipes, warn: no to suppress warning. But if I were you, I'd use apt_key + apt_repository Ansible modules to create self explaining playbook that also support check_mode runs.
Ansible
47,994,497
19
I merged two lists from an Ansible inventory: set_fact: fact1: "{{ groups['group1'] + groups[group2']|list }} The output is: fact1: - server01 - server02 - server03 With the above results, I need to append https:// to the front, and a port number to the back of each element. Then I need to convert it to a com...
Solution set_fact: fact2: "{{ fact1 | map('regex_replace', '(.*)', 'https://\\1:8000') | join(',') }}" Explanation map filter applies a filter (regex_replace) to individual elements of the list; regex_replace filter (with the following regular expression) adds a prefix and suffix to a string; current_list | map('re...
Ansible
47,047,876
19
How can I run a playbook only on first host in the group? I am expecting something like this: --- - name: playbook that only run on first host in the group hosts: "{{ groups[group_name] | first }}" tasks: - debug: msg: "on {{ inventory_hostname }}" But this doesn't work, gives error: 'groups' is undefi...
You can use: hosts: group_name[0] Inventory hosts values (specified in the hosts directive) are processed with a custom parser, which does not allow Jinja2 expressions like the regular template engine does. Read about Patterns.
Ansible
42,942,875
19
I have an Ansible script, and I am trying to get the filename of the newest item in a directory. I am using this Ansible script: - name: Finding newest file in a folder find: paths: "/var/www/html/wwwroot/somefolder/" age: "latest" age_stamp: mtime However, I am getting the following error - FAILED! =>...
Pure Ansible solution: - name: Get files in a folder find: paths: "/var/www/html/wwwroot/somefolder/" register: found_files - name: Get latest file set_fact: latest_file: "{{ found_files.files | sort(attribute='mtime',reverse=true) | first }}"
Ansible
41,971,169
19
I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following inside of the my conf.j2 {% for domain in domains %} [[acme.domains]] ...
You get u' ' because you print the object containing the Unicode strings and this is how Python renders it by default. You can filter it with list | join filters: {% for domain in domains %} [[acme.domains]] {% for key, value in domain.iteritems() %} {% if value is string %} {{ key }} = "{{ value }}" {% else %} {{ ...
Ansible
41,521,138
19
The Ansible best practices documentation recommends to separate inventories: inventories/ production/ hosts.ini # inventory file for production servers group_vars/ group1 # here we assign variables to particular groups group2 # "" host_vars/ ...
I scrapped the idea of following Ansible's recommendation. Now one year later, I am convinced that Ansible's recommendation is not useful for my requirements. Instead I think it is important to share as much as possible among different stages. Now I put all inventories in the same directory: production.ini reference.in...
Ansible
40,606,890
19
I'd like to remove a single key from a dictionary in Ansible. For example, I'd like this: - debug: var=dict2 vars: dict: a: 1 b: 2 c: 3 dict2: "{{ dict | filter_to_remove_key('a') }}" To print this: ok: [localhost] => { "dict2": { "b": 2, "c": 3 } } Please note that...
- set_fact: dict: a: 1 b: 2 c: 3 dict2: {} - set_fact: dict2: "{{dict2 |combine({item.key: item.value})}}" when: "{{item.key not in ['a']}}" with_dict: "{{dict}}" - debug: var=dict2 or create a filter plugin and use it.
Ansible
40,496,021
19
I am getting value of variable "env" in Jinja2 template file using a variable defined in group_vars like: env: "{{ defined_variable.split('-')[0] }}" env possible three values could be abc, def, xyz. On the basis of this value I want to use server URL, whose possible values I have defined inside defaults/main.yml as: ...
You don't need quotes and braces to refer to variables inside expressions. The correct syntax is: {% if 'abc' == env %} serverURL: '{{ server_abc }}' {% elif 'def' == env %} serverURL: '{{ server_def }}' {% elif 'xyz' == env %} serverURL: '{{ server_xyz }}' {% else %} ServerURL: 'server URL not found' {% endif %} Othe...
Ansible
40,086,613
19
I got puzzled setting up server with the following cpu facts: "ansible_processor": [ "GenuineIntel", "Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz", "GenuineIntel", "Intel(R) Xeon(R) CPU E5-2650L v3 @ 1.80GHz" ], "ansible_processor_cores": 1, "ansible_processor_count": 2, "ansible_processor_threads_...
Looking into the code ansible_processor_vcpus should be your choice. It should contain number of processors in /proc/cpuinfo (which actually is a number of total threads, as per this answer.
Ansible
39,539,559
19
I have this in vars: var1: "test1" var2: "test2" var3: "{{var1}}" Now I want to dynamically change var3: "{{var2}}". I can assign var3: "test2". But how can I assign var3: "{{var2}}"?
My attempt at the interpretation of the phrase "dynamically change Ansible variable" based on your question: --- - hosts: localhost connection: local vars: var1: "test1" var2: "test2" var3: "{{var1}}" tasks: - debug: var=var3 - set_fact: var3: "{{var2}}" - debug: var=var3 Regardin...
Ansible
39,072,079
19
I'm fairly new in using Ansible and have been reading here and google and haven't found an answer yet. My scenario is that I have 1 user on a server but 2-3 different pub keys that need to put in it's authorized_keys file. I can successfully remove all keys, or add all keys with this script: --- - hosts: all tasks:...
Is there any way to loop over pub files and use the exclusive option at the same time? No. There is a note about loops and exclusive in the docs: exclusive: Whether to remove all other non-specified keys from the authorized_keys file. Multiple keys can be specified in a single key string value by separating them by ne...
Ansible
38,879,266
19
I'm new to ansible. I have a requirement that requires me to pull OS version for of more than 450 linux severs hosted in AWS. AWS does not provide this feature - it rather suggests us to get it from puppet or chef. I created few simple playbooks which does not run --- - hosts: testmachine user: ec2-user sudo: yes task...
Use one of the following Jinja2 expressions: {{ hostvars[inventory_hostname].ansible_distribution }} {{ hostvars[inventory_hostname].ansible_distribution_major_version }} {{ hostvars[inventory_hostname].ansible_distribution_version }} where: hostvars and ansible_... are built-in and automatically collected by Ansible...
Ansible
38,078,247
19
I am trying to make Ansible work with --limit and to do that I need facts about other hosts, which I am caching with fact_caching. What command should I run so that it simply gathers all the facts on all the hosts and caches them, without running any tasks? Something like the setup module would be perfect if it cached ...
Here is how I'd solve the problem: 1.- Enable facts gathering on your playbook (site.yml): gather_facts: yes 2.- Enable facts caching on ansible.cfg: 2.1.- Option 1 - Use this if you have the time to install redis: [defaults] gathering = smart fact_caching = redis # two hours timeout fact_caching_timeout = 7200 2.2....
Ansible
32,703,874
19
I want to pretty print a registered object in ansible to help with debugging. How do I do it?
You also have to_nice_yaml and to_nice_json if you want to control the format itself. More details here.
Ansible
29,745,534
19
I need to do base64 encoding of something like: "https://myurl.com". Because there is a colon in that string, I need to enclose everything in quotes. So I have something like: - name: do the encode shell: 'echo "https://myurl.com" | /usr/bin/base64' register: bvalue But I get a blank when I use: {{ bvalue.stdout }...
I think this is how to do it. Define a variable in a playbook: MYVAR: "https://myurl.com" Then in the role, do: - name: do the encode shell: echo {{ MYVAR | b64encode }} > /tmp/output
Ansible
22,978,319
19
Having an issue with ansible.builtin.shell and ansible.builtin.command. Probably not using them right, but usage matches the docs examples. Ansible version 2.10.3 In roles/rabbitmq/tasks/main.yml --- # tasks file for rabbitmq # If not shut down cleanly, the following will fix: # systemctl stop rabbitmq-server - name: ...
Try this: - name: Force RabbitMQ to boot anyway command: "/usr/sbin/rabbitmqctl force_boot" register: result ignore_errors: True I basically took out the ansible.builtin.. It works for me. register captures the output into a variable named result. ignore_errors is useful so that if an error occurs Ansible will n...
Ansible
66,178,118
18
I am creating a systemd service using template module --- - name: Systemd service template: src: sonar.unit.j2 dest: /etc/systemd/system/sonarqube.service when: "ansible_service_mgr == 'systemd'" The contents of the sonarqube.service can change of course. On change I want to restart the service. How can I...
There are two solutions. Register + When changed You can register template module output (with its status change), register: service_conf and then use when clause. when: service_conf.changed For example: --- - name: Systemd service template: src: sonar.unit.j2 dest: /etc/systemd/system/sonarqube.service ...
Ansible
57,571,765
18
Background: This is an Ansible playbook using templates to CONSTRUCT a yaml file from a template. So basically I have a jinja2 template file with a line as such: private_key: {{ myvar }} Ansible uses yaml to define the variables. So I will fill in the myvar value something like this. Here I am using the | special ch...
I found the answer in a Google search right after posting the question. Essentially the yaml string will strip indents, so in this case we have to use Jinja to insert spaces where they were stripped. Luckily this is super easy to do: In the template file, I replaced this: private_key: {{ myvar }} With this: privat...
Ansible
55,411,080
18
My problem is with ansible and parsing stdout. I need to capture the stdout from an ansible play and parse this output for a specific substring within stdout and save into a var. My specific use case is below - shell: "vault.sh --keystore EAP_HOME/vault/vault.keystore | --keystore-password vault22 --alias vau...
You are very close. I advice you to use regex101.com to test regular expressions. Here is my solution: --- - hosts: localhost gather_facts: no tasks: - shell: echo 'vault-option name="KEYSTORE_PASSWORD" value="MASK-5dOaAVafCSd"' register: results - set_fact: myvalue: "{{ results.stdout | regex...
Ansible
45,740,777
18
When running a playbook Ansible randomly sets a node as first, second and third. ok: [node-p02] ok: [node-p03] ok: [node-p01] Q: How can I configure Ansible to let it execute with the hosts in sorted order? Example: ok: [node-p01] ok: [node-p02] ok: [node-p03] Serial: 1 is not an option, since it slows down the play,...
Applicable for Ansible 2.4 and higher: This is now the default behaviour, ansible will play the hosts in the order they were mentioned in the inventory file. Ansible also provides a few built in ways you can control it with order: - hosts: all order: sorted gather_facts: False tasks: - debug: var: inv...
Ansible
42,506,865
18
Is it possible to use variables on command or shell modules? I have the following code, and I would like to use variable file to provide some configurations: I would like to read the Hadoop version from my variables file. On other modules of ansible I could use {{ansible_version}}, but with command or shell it doesn't ...
Quote the full string in the command argument: - name: Iniciar zkfc command: "{{ hadoop_version }}/sbin/hadoop-daemon.sh start zkfc"
Ansible
41,567,196
18
I'm writing an Ansible template that needs to produce a list of ip's in a host group, excluding the current hosts IP. I've searched around online and through the documentation but I could not find any filters that allow you to remove an item in a list. I have created the (hacky) for loop below to do this but was wonder...
There is difference filter for that: - debug: var=item with_items: "{{ groups['my_group'] | difference([inventory_hostname]) }}" This will give you all items hosts from my_group without current host.
Ansible
40,696,130
18
This should be very simple. I want to make an Ansible statement to create a Postgres user that has connection privileges to a specific database and select/insert/update/delete privileges to all tables within that specific database. I tried the following: - name: Create postgres user for my app become: yes bec...
What I had to do was first create the user and then grant the privileges separately. It's working like a charm. - name: Create postgres user for my app become: yes become_user: postgres postgresql_user: name: "myappuser" password: "supersecretpassword" - name: Ensure we have access from the ...
Ansible
40,290,837
18
I'm new to the configuration management and deployment tools. I have to implement a Continuous Delivery/Continuous Deployment tool for one of the most interesting projects I've ever put my hands on. First of all, individually, I'm comfortable with AWS, I know what Ansible is, the logic behind it and its purpose. I do n...
I would like to answer in parts How does Docker (or Ansible and Docker) extend the Continuous Integration process!? Since docker images same everywhere, you use your docker images as if they are production images. Therefore, when somebody committed a code, you build your docker image. You run tests against it. When a...
Ansible
37,499,514
18
Im trying to install ansible-galaxy roles on Mac OS X El Capitan via CLI $ ansible-galaxy install -r requirements.yml I am getting this error: ERROR! Unexpected Exception: (setuptools 1.1.6 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python), Requirement.parse('setuptools>=11.3')) the full tra...
Run the following to upgrade setuptools under the python user: pip install --upgrade setuptools --user python For some reason, the way things are installed inside OS X (and in my case, under CentOS 7 inside a Docker container), the setuptools package doesn't get installed correctly under the right user.
Ansible
36,958,125
18
This is a known issue and I found a solution but it's not working for me. First I had: fatal: [openshift-node-compute-e50xx] => SSH Error: ControlPath too long It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue. So I created a ~/.ansible.cfg. The content ...
The limit is 104 or 108 characters. (I found different statements on the web) You XXXed out some sensitive information in the error message so it's not clear how long your path actually is. I guess %(directory)s is replaced with the .ansible directory in your users folder. Removing that and using directly your user fol...
Ansible
35,970,686
18
I'm trying to use ansible to loop over a list of lists to install some packages. But {{item}} is returning every element in the sub lists rather than the sublist itself. I have a yaml file which come from a manifest list from outside ansible and it looks like this: --- modules: - ['module','version','extra'] - ['mo...
An alternative way to solve this issue is to use a complex item instead of a list of list. Structure your variables like this: - modules: - {name: module1, version: version1, info: extra1} - {name: module2, version: version2, info: extra2} - {name: module3, version: version3, info: extra3} Then you can still use...
Ansible
35,662,388
18
I am new to ansible and I am using a template statement in my playbook to copy a file from my local machine to a remote machine. I get an error saying the destination directory does not exist, but it is there very much. I am using Centos 6.5 version (both my local and remote). Any help is appreciated.
Create the destination directory with Ansible - - name: Create a directory if it does not exist ansible.builtin.file: path: /etc/some_directory state: directory mode: '0755' Ref: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html
Ansible
31,352,169
18
I am creating a playbook which first creates a new username. I then want to run "moretasks.yml" as that new user that I just created. Currently, I'm setting remote_user for every task. Is there a way I can set it for the entire set of tasks once? I couldn't seem to find examples of this, nor did any of my attempts to m...
You could split this up into to separate plays? (playbooks can contain multiple plays) --- - name: PLAY 1 hosts: all remote_user: root gather_facts: true tasks: - include: createuser.yml new_user=username - include: roottasks.yml #some tasks unrelated to username. - name: PLAY 2 hosts: all remote_...
Ansible
27,307,773
18
I am using Ansible and I want to run a task only once. I follow the documentation about how to configure and run a task only once - name: apt update shell: apt-get update run_once: true But when I run Ansible, it always runs this task. How can I run my task only once.
The run_once option will run every time your Playbook/tasks runs, but will only run it once during the specific run itself. So every time you run the play, it will run, but only on the first host in the list. If you're looking for a way to only run that command once, period, you'll need to use the creates argument. ...
Ansible
26,409,164
18
we can change the path of roles by modifying roles_path in ansible.cfg. But the document doesn't seems to mention anything about changing the path of group_vars and host_vars. How can I change those paths? I will integrate the files related to ansible with rails app repsitory. I want to gather the roles and vars direct...
You cannot change the path for host_vars nor group_vars. Those paths are always relative to your hostfile. You can set a standard hostfile in your ansible config: hostfile = /path/to/hostfile/hostfile.ini in this case your default host_vars are to be found at /path/to/hostfile/host_vars/ You might as well use multipl...
Ansible
25,346,796
18
I can't realize how to write a task, that answers mysql_secure_installation script questions. I only have shell: mysql_secure_installation <<< '1111' executable=/bin/bash and no ideas on how to continue answering. What would be the best way to solve this? Thanks in advance!
I think you best bet is to write a playbook (or better, change your mysql role) that will reproduce mysql_secure_installation script. There are several reasons for this : the script will always return 'changed', everytime you run your playbook, which is not something you want writing tasks is more flexible : you can a...
Ansible
25,136,498
18
My organization's website is a Django app running on front end webservers + a few background processing servers in AWS. We're currently using Ansible for both : system configuration (from a bare OS image) frequent manually-triggered code deployments. The same Ansible playbook is able to provision either a local Vagra...
This question is very opinion based. But just to give you my take, I would just go with prebaking the AMIs with Ansible and then use CloudFormation to deploy your stacks with Autoscaling, Monitoring and your pre-baked AMIs. The advantage of this is that if you have most of the application stack pre-baked into the AMI...
Ansible
23,056,177
18
In the lineinfile module, it replaces the full line. If the line is long I have to repeat the whole line again. Let us suppose I want to replace the single word in the file: #abc.conf This is my horse this is the playbook: - lineinfile: dest=abc.conf state=present regexp='horse' ...
New module replace available since 1.6 version: - replace: dest=abc.conf regexp='horse' replace='dog' backup=yes
Ansible
22,398,302
18
I am currently searching for a good distributed file system. It should: be open-source be horizontally scalable (replication and sharding) have no single point of failure have a relatively small footprint Here are the four most promising candidates in my opinion: GridFS (based on MongoDB) GlusterFS Ceph HekaFS The ...
I'm not sure your list is quite correct. It depends on what you mean by a file system. If you mean a file system that is mountable in an operating system and usable by any application that reads and writes files using POSIX calls, then GridFS doesn't really qualify. It is just how MongoDB stores BSON-formatted objects....
Ceph
17,425,153
42
Ceph teuthology installation fails with following error on Ubuntu 14.04, kernel 4.4.0-51-generic: ImportError: <module 'setuptools.dist' from '/usr/lib/python2.7/dist-packages/setuptools/dist.pyc'> has no 'check_specifier' attribute
It was due to older setuptools version. I updated setuptools as follows: sudo pip install setuptools --upgrade It installed setuptools-31.0.0 and that worked.
Ceph
41,141,657
26
I'm running proxmox and I try to remove a pool which I created wrong. However it keeps giving this error: mon_command failed - pool deletion is disabled; you must first set the mon_allow_pool_delete config option to true before you can destroy a pool1_U (500) OK But: root@kvm-01:~# ceph -n mon.0 --show-config | grep m...
Another approach: ceph tell mon.\* injectargs '--mon-allow-pool-delete=true' ceph osd pool rm test-pool test-pool --yes-i-really-really-mean-it
Ceph
45,012,905
16
The WAL (Write-Ahead Log) technology has been used in many systems. The mechanism of a WAL is that when a client writes data, the system does two things: Write a log to disk and return to the client Write the data to disk, cache or memory asynchronously There are two benefits: If some exception occurs (i.e. power l...
Performance. Step two in your list is optional. For busy records, the value might not make it out of the cache and onto the disk before it is updated again. These writes do not need to be performed, with only the log writes performed for possible recovery. Log writes can be batched into larger, sequential writes. For ...
Ceph
58,694,102
16
I am getting both of these errors at the same time. I can't decrease the pg count and I can't add more storage. This is a new cluster, and I got these warning when I uploaded about 40GB to it. I guess because radosgw created a bunch of pools. How can ceph have too many pgs per osd, yet have more object per pg than ave...
I'm going to answer my own question in hopes that it sheds some light on the issue or similar misconceptions of ceph internals. Fixing HEALTH_WARN too many PGs per OSD (352 > max 300) once and for all When balancing placement groups you must take into account: Data we need pgs per osd pgs per pool pools per osd th...
Ceph
39,589,696
14
I configured Ceph with the recommended values (using a formula from the docs). I have 3 OSDs, and my config (which I've put on the monitor node and all 3 OSDs) includes this: osd pool default size = 2 osd pool default min size = 1 osd pool default pg num = 150 osd pool default pgp num = 150 When I run ceph status I g...
Before setting PG count you need to know 3 things. 1. Number of OSD ceph osd ls Sample Output: 0 1 2 Here Total number of osd is three. 2. Number of Pools ceph osd pool ls or rados lspools Sample Output: rbd images vms volumes backups Here Total number of pool is five. 3. Replication Count ceph...
Ceph
40,771,273
12
Keycloak configuration and data is stored in a relational database, which is usally persisted to the hard disk. This includes data like realm settings, users, group- and role-memberships, auth flows and so on. But the user sessions will only be stored in an ephemeral in-memory infinispan cache. Therefore the session da...
As you already wrote in your question, using Infinispan would be the go-to solution. Infinispan can be used in two ways: Infinispan running within Keycloak, which is the OOTB way of Keycloak --> Problem: when all Keycloak instances shut down, Infinispan is also down and sessions are lost Infinispan running as an exter...
Keycloak
70,581,540
14
I have deployed keycloak on my EKS cluster and able to access dashboard successfully and created a new realm already. So I thought of testing my keycloak, and went to https://www.keycloak.org/app/ for testing. I have created a client with the root URL "https://www.keycloak.org/app/" and created one User also. I have te...
I too had this error. I followed instructions somewhere for configuring the keycloak client application's url, realm, and clientId properties. In the instructions it said to configure the url to http://localhost:8080/auth. I think this must have changed somewhere along the way. Changing the url property to http://lo...
Keycloak
65,711,806
14
I am managing a Keycloak realm with only a single, fully-trusted external IdP added that is intended to be the default authentication mechanism for users. I do not want to allow user to register, i.e. I want to manually create a local Keycloak user, and that user should then be allowed to link his external IdP account ...
According to the doc: https://www.keycloak.org/docs/latest/server_admin/index.html#detect-existing-user-first-login-flow, you must create a new flow like this: et voilà :)
Keycloak
52,382,531
14
I have a use case where user should be disabled when he enter wrong password 5 consecutive times. I cant find any keycloak password policy to disable user when he enter wrong password 5 consecutive times.
To enable Consecutive Failed Login Defence you need to enable "Max Login Failures" from Brute Force Detection. Steps: Login to Keycloak Admin Console Select Realms from List Go To Realm Settings >> Security Defenses >> Brute Force Detection Enable Brute Force Detection Set Max Login Failures to 5 Refer screenshot for...
Keycloak
69,254,441
13
I created users and roles in Keycloak which I want to export. When I tried to export them using the realm's "Export" button in UI I got a JSON file downloaded. But I couldn't find any users or roles in the exported file realm.json How can I export a realm JSON including users and roles from Keycloak?
Update: The /auth path was removed starting with Keycloak 17 Quarkus distribution. So you might need to remove the /auth from the endpoint calls presented on this answer. You will not be able to do that using the export functionality. However, you can get that information using the Keycloak Admin REST API; to call tha...
Keycloak
65,200,310
13
My company uses Keycloak for authentication connected with LDAP and returning a user object filled with corporative data. Yet in this period we are all working from home and in my daily work having to authenticate in my corporative server every time I reload the app, has proven to be an expensive overhead. Especially w...
You can leverage Angular environment(or even process.env) variable to switch between real and mock implementations. Here is a simple example of how to do that: app-init.ts ... import { environment } from '../environments/environment'; export function initializer( keycloak: KeycloakService ): () => Promise<any> { ...
Keycloak
61,917,978
13
Recently my application using Keycloak stopped working with a 400 token request after authenticating. What I found so far is that within the token request, the Keycloak cookies (AUTH_SESSION_ID, KEYCLOAK_IDENTITY, KEYCLOAK_SESSION) are not sent within the request headers causing the request for a token to fail and the ...
If you are facing this issue while using keycloak-js adapter. Then the reason for this issue: By default, the JavaScript adapter creates a hidden iframe that is used to detect if a Single-Sign Out has occurred. This does not require any network traffic, instead the status is retrieved by looking at a special status coo...
Keycloak
60,622,192
13
I'm trying to use keycloak in my node project but I'm always getting the following message : Cannot read property 'keycloak-token' of undefined. Before that, I've launched keycloak, I created a new realm 'Test' and a new user 'id_a' which for I've set a new password. I can access to the account with keycloak but I can'...
I had the same issue, but now it's working. You need to instantiate a session before running the keycloak middleware. The missing piece of code is as follows: // Create a session-store to be used by both the express-session // middleware and the keycloak middleware. var memoryStore = new session.MemoryStore(); app.u...
Keycloak
56,286,958
13
Which is the best option for SSO implementation Keycloack Vs CAS Vs Okta? I'm specifically looking for the disadvantages of each service to identify the best suitability for my system.
Both Keycloak and Okta should provide what you're looking for. I'm not sure about CAS as I haven't used it in 10 years. Since both Keycloak and Okta use OAuth 2.0/OIDC, you might even be able to use Keycloak in development, and Okta in production. I've implemented OAuth 2.0 / OIDC support in JHipster. It uses Keycloak ...
Keycloak
53,650,790
13
I would like to let my users have a choice which authentication method to use. For example, they could be presented with a menu to pick an option (username/pass, username/pass+OTP, etc). Then, Keycloak should, based on their choice, assign specific scope to the token. Is this possible to do with Keycloak (probably by s...
Here is what i did and it works, 'My goal was give ability to client to choose authentication flow, choose between otp based email and sms.' I created a new authentication flow, see screenshot : select 'Alternative' on both flows. On login form new link will appear 'try another way' Now the client can choose between ...
Keycloak
51,980,195
13
I'm using Keycloak version 1.6.1, newly installed as a standalone application. Keycloak should act as an IdP (Identity provider) for an SP (Service Provider) called Tableau. I have read from this page: http://blog.keycloak.org/2015/03/picketlink-and-keycloak-projects-are.html ... Keycloak from being Identity Broker gr...
Sometimes it's a good thing to specify in writing what you need - which I did here on Stack Overflow. I found the URL to where on Keycloak one can export the IdP XML https://keycloak-url/realms/{REALM-NAME}/protocol/saml/descriptor That gave me the IDPSSODescriptor. I'll leave this thread here, so people can benefit f...
Keycloak
33,542,812
13
I'm currently trying to develop a Spring Boot Rest Api which is secured with keycloak. I get an error when I try to call a api which the user has to be identify. The error message is following: 2020-04-10 16:09:00.324 WARN 44525 --- [nio-8080-exec-7] o.keycloak.adapters.KeycloakDeployment : Failed to load URLs from...
I have the same problem, and I try a lot to find the answer at google, stackoverflow etc... Finally, I catch the clue, to make it work, just remove the path of the keycloak.auth-server-url as http://192.168.0.119:8080 instead of http://192.168.0.119:8080/auth or something else. ... : Loaded URLs from http://192.168....
Keycloak
61,142,611
12
We run Keycloak docker image in AWS ECS and we need a way to export a realm and all users for automation purposes using ansible. We can run the following command with ansible to run the export docker exec -i 702f2fd7858d \ /bin/bash -c "export JDBC_PARAMS=?currentSchema=keycloak_service && /opt/jboss/keycloak/bin...
I was facing the same problem a few days ago and implemented a working solution: #!/usr/bin/env bash # # backup-keycloak.sh # Copy the export bash script to the (already running) keycloak container # to perform an export docker cp docker-exec-cmd.sh keycloak:/tmp/docker-exec-cmd.sh # Execute the script inside of the c...
Keycloak
60,766,292
12
I am trying to create a user via the Keycloak API, and I would like to assign a realm-level role to them when they are first added. However, it doesn't seem to work like the documentation says it should. I know that I could simply make a second add-role-to-user API request after the initial create-user one, but: The d...
You did nothing wrong. It is a bug in the Keycloak API. This request should work: Keycloak::Admin.generic_post('users', nil, { username: 'someone', realmRoles: ['owner'] }, access_token) Unfortunately the API documentation is wrong because the 'realmRoles' attribute doesn't work when trying to create/update a user/gro...
Keycloak
57,390,389
12
Well, as the title suggests, this is more of an issue record. I was trying to follow the instructions on this README file of Keycloak docker server images, but encountered a few blockers. After pulling the image, below command to start a standalone instance failed. docker run jboss/keycloak The error stack trace: ...
I ran into the same issue. As it turned out, the key to the solution was the missing parameter "DB_USER=keycloak". The Application tried to authenticate against the database using the username ''. This was indicated by the first error message. WFLYCTL0113: '' is an invalid value for parameter user-name Possibly the 4...
Keycloak
56,180,225
12
How to add custom attributes in Keycloak via REST API?
I guess you mean adding user attributes to the admin console by extending the theme - https://www.keycloak.org/docs/3.1/server_development/topics/custom-attributes.html Since that configures the admin console itself it does involve some configuration of files loaded by the keycloak app for a custom theme so I don't thi...
Keycloak
53,883,487
12
Currently I try to create a user from curl command via Keycloak's Admin REST API. I can authenticate myself as an admin, I have a good answer, but when I want to create a user, I have an error like: "404 - Not Found". Here are my curl commands: #!/bin/bash echo "* Request for authorization" RESULT=`curl --data "userna...
try this, I added the content type header and modify the url : #!/bin/bash echo "* Request for authorization" RESULT=`curl --data "username=admin&password=Pa55w0rd&grant_type=password&client_id=admin-cli" http://localhost:8080/auth/realms/master/protocol/openid-connect/token` echo "\n" echo "* Recovery of the token"...
Keycloak
52,440,546
12
I'm trying to deploy a very simple REST service secured with keycloak and am getting the following error: Caused by: org.keycloak.authorization.client.util.HttpResponse.Exception: Unexpected response from server: 400 / Bad Request / Response from server: ("error":"invalid_client","error_description":"Bearer-onl...
Since you have not shared your keycloak config, I am guessing the above error is because you created a bearer only client in keycloak. Keycloak doesn't allow "bearer only" clients to obtain tokens from the server. Try to change your client to "confidential" on the server and set bearer-only on your adapter configuratio...
Keycloak
52,414,165
12
I have not been able to divine the way I might add extra claims from my application database. Given my limited understanding, I see two ways: After successful authentication have keycloak pull extra claims from the application database somehow. This app database is postgres, for example. Have the application update t...
Answering my own question here. I cross-posted this question to the Keycloak users mailing list here (http://lists.jboss.org/pipermail/keycloak-user/2017-April/010315.html) and got an answer that seems reasonable. This is pasted from the answer I received there. I use the first option. I do it with a protocol mapper, ...
Keycloak
43,376,233
12
I'd like to authenticate a legacy java (6) application against a node-js one currently secured using keycloak OIDC bearer only (both apps belonging to same realm). I've been told to use keycloak-authz-client library resolving a keycloak OIDC JSON as below { "realm": "xxx", "realm-public-key": "fnzejhbfbhafbazhfzaf...
You are mixing up the OAuth 2.0 concepts of Client Types and Grants. Those are different, albeit interconnected, concepts. The former refers to the application architecture, whereas the latter to the appropriate grant to handle a particular Authorization/Authentication use-case. One chooses and combines those options; ...
Keycloak
41,695,223
12
Context: I'm creating a cloud platform to support multiple applications with SSO. I'm using Keycloak for authentication and Netflix Zuul for authorization (API Gateway) thru Keycloak Spring Security Adapter. Each microservice expect an Authorization header, which contains a valid JWT, from which it will take the userna...
Disclaimer: I never used Keycloak, but the tag wiki says it's compliant with OAuth2 so I'll trust that information. At a really high-level view, you seem to have two requirements: authenticate actions triggered by an end user while he's using your system. authenticate actions triggered by your system at an unknown ti...
Keycloak
40,458,770
12
I am creating an email theme for keycloak. So, when a user forgets their password and requests for a link to reset it; an email is sent to the user. Now, I am cutomizing the email that he/she gets. I want to add the user's name. Can I do that? I do have access to variables including: link to reset password link expirat...
You can add user.username in your .ftl file open (email/text) *.ftl file and add user.username as one of the parameter like ${msg("passwordResetBody",link, linkExpiration, realmName,user.username)} and then update actual message body at (email/messages/messages_en.properties) with parameter number like {2} or {3...
Keycloak
37,199,200
12
I have a nextjs application with next-auth to manage the authentication. Here my configuration .... export default NextAuth({ // Configure one or more authentication providers providers: [ KeycloakProvider({ id: 'my-keycloack-2', name: 'my-keycloack-2', clientId: process.env.NEXTAUTH_CLIENT_ID...
After some research i found a reddit conversation https://www.reddit.com/r/nextjs/comments/redv1r/nextauth_signout_does_not_end_keycloak_session/ that describe the same problem. Here my solution. I write a custom function to logout const logout = async (): Promise<void> => { const { data: { path } } = a...
Keycloak
71,872,587
11
We can use PostgreSQL or MySQL as DB for keycloak but I want to use mongo DB as database for keycloak. is there any way to implement this ?
Although MongoDB was once supported in Keycloak, it has since been removed. Per the offical Keycloak documentation, a relational database is required for the persistent datastore: https://www.keycloak.org/docs/latest/server_installation/index.html#_database
Keycloak
62,259,957
11
I want to use Keycloak in a microservices based environment, where authentication is based on OpenID endpoints REST calls ("/token", no redirection to keycloak login page), a flow that I thought of would be something like this: 1. Front-end SPA retrieves the tokens from the "/token" endpoint and stores in browser's l...
Your Front-end SPA should be public-client and springboot micro service should be Bearer only Client and Gateway could be Confidential Client. You can check the Keycloak provided oidc adapters. For springboot you use the keycloak provided adapter Similar solution using api gateway is discussed here
Keycloak
60,153,377
11