Skip to main content
8 votes

quoting colon in ansible

It is documented in Ansible's documentation about this. You can escape colon like this - - raw: echo "something {{':'}} else" and output of this is like - changed: [localhost] => { "...
Abhijeet Kasurde's user avatar
7 votes

quoting colon in ansible

Playing around with quoting, I got a helpful error message at last. Apparently, you will confuse the YAML parser unless you quote the entire line. Here is the working example: --- - hosts: ...
stochastic's user avatar
7 votes
Accepted

How does the formatting policy look like since Ansible 2.0?

Please understand I believe my answer to be highly subjective. Internally my team loosely agrees with my opinions on this. But we've not draft any "formatting policy" for playbooks. Should name (...
jscott's user avatar
  • 24.8k
5 votes

How does the formatting policy look like since Ansible 2.0?

That is up to your own preference. Comments like # Make sure Jenkins starts, then configure Jenkins. don't make much sense as they don't add more information. Inline syntax is supported by YAML to ...
Henrik Pingel's user avatar
5 votes

How to use vars in ansible roles

The problem is with the way you use with_items: bare variables are unsupported for quite a while already. Correct your loop like this: with_items: "{{ ssh_vars }}"
Konstantin Suvorov's user avatar
5 votes
Accepted

CloudFormation stack yaml syntax?

You have an extra '-' character in the Tags definition. It should look something like the snippet below (I'm not sure of the Join syntax, personally I use Sub normally): Tags: - Key: Name ...
David Hutchison's user avatar
5 votes
Accepted

CloudFormation template: how to use Sub and GetAtt at the same time in short form?

Simply remove !GetAtt and reference the desired variable. In the following code EIP.AllocationId normally returned via !GetAtt. !Sub | #!/bin/bash export INSTANCEID=$(curl -s http://169.254.169....
spinnerdog's user avatar
5 votes
Accepted

How to merge variables of type hash across different variable files in ansible?

First of all, list is [1, 2, 3] and you talk about dictionary {a:1, b:2, c:3} or in other words hash. There is configurable parameter: hash_behaviour. By default it is replace, but you can set it to ...
Konstantin Suvorov's user avatar
4 votes
Accepted

How do I loop over items 1 by 1 in Ansible config (YAML/Jinja2)?

You don't need to loop over hosts, as this is one of the most fundamental Ansible functions (it is disabled on a few selected modules, but hostname is not one of them). To set the target machine's ...
techraf's user avatar
  • 4,363
4 votes

SaltStack: found conflicting ID

This: - contents: | introduces a value for contents that is a block style literal scalar that runs for all following indented lines. The indention must be more than the indent of the key contents. ...
Anthon's user avatar
  • 142
4 votes
Accepted

Adding an existing security group CloudFormation EC2 template

To do this you just add them in your EC2 Resource property directly under SecurityGroupIds: Resources: EC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: ...
rumplesmyboy's user avatar
4 votes
Accepted

How to use Ansible modules replace or inline instead shell command with SED

The replace and the lineinfile use the path parameter to mark The file to modify. lineinfile module is used to ensure[s] a particular line is in a file, or [to] replace an existing line ...
Henrik Pingel's user avatar
4 votes
Accepted

Ansible check if variable exists in attribute list

There are presumably more elegant ways of doing it, but something like this works for me: If your inventory file looks like this host1 host2 host3 host4 Then a playbook with the following content, ...
Tom's user avatar
  • 11.4k
4 votes

How to validate variables contents in Ansible?

You can use assert and testing-strings to achieve that. Like so: - hosts: localhost vars: variable: 'green' tasks: - assert: that: variable is match("green") ...
Henrik Pingel's user avatar
3 votes
Accepted

Is it possible to change the current user's password in-band with ansible?

Is there a way to make Ansible try the default password, and keep running the playbook if that fails? Here is an example, it doesn't exactly match what you mentioned, but might be a starting point. -...
Zoredache's user avatar
  • 132k
3 votes

Ansible match and change a bash prompt with regex

Even if this ticket is over two years old, I found me in the same situation. I tried a bit and found a solution to this challenge - name: Set default color in bash lineinfile: path: /home/...
Mrk's user avatar
  • 31
3 votes

How can I enable epel-release before installing packages with cloud-init?

Add this to your cloud init script: yum_repos: epel-release: baseurl: http://download.fedoraproject.org/pub/epel/7/$basearch enabled: true failovermethod: priority ...
MichelZ's user avatar
  • 11.2k
3 votes

Templated dict keys in ansible YAML

The play - hosts: localhost vars: username: user1 userpass: pass1 users: "{{ {username: {'pass': userpass}} }}" tasks: - debug: var: users gives: "users&...
Vladimir Botka's user avatar
3 votes

Use lookup/dynamic variable names in Ansible jinja2 template

My question was answered by Martin Krizek, in the Ansible newsgroup. The correct syntax is: --- - hosts: localhost connection: local vars: CentOS: hostkeys: - "ssh_host_key&...
Willem's user avatar
  • 187
3 votes

Ansible check if variable exists in attribute list

Optionally, this condition is cleaner when: inventory_hostname not in hostlist|map(attribute="name")|list Use inventory_hostname instead of ansible_hostname if you want to compare to ...
Vladimir Botka's user avatar
3 votes

Create JSON Patch 6902 from two yaml/json files

The same was asked here: https://stackoverflow.com/questions/22547709/generate-json-patch-from-two-objects For example: https://www.npmjs.com/package/rfc6902 https://github.com/Starcounter-Jack/JSON-...
C-nan's user avatar
  • 131
2 votes

Ansible match and change a bash prompt with regex

Why not just set PS1 to desired value? - lineinfile: create: yes mode: 0600 dest: /root/.bash_aliases owner: root regexp: '^PS1=' line: 'PS1="${debian_chroot:+($debian_chroot)}...
Konstantin Suvorov's user avatar
2 votes
Accepted

docker compose sharing volumes with mapped to paths

From your yml: ... invoiceplane: volumes: - /srv/docker/invoicePlane/uploads:/var/www/html/uploads volumes_from: - invoiceplane-wipay ... invoiceplane-wipay: ... ...
BMitch's user avatar
  • 6,429
2 votes
Accepted

Dynamic inventory in yaml format

Short answer Don't look at https://docs.ansible.com/ansible/2.6/user_guide/intro_inventory.html but at https://docs.ansible.com/ansible/2.6/dev_guide/developing_inventory.html. Long answer Ansible ...
Mailo Světel's user avatar
2 votes
Accepted

Ansible expect is not sending response

Keys in response map are regular expressions, so ? and (...) are treated as regexp control characters resulting in no match. If you really want to pass the whole string, you should use: responses: ...
Konstantin Suvorov's user avatar
2 votes
Accepted

Ansible error: The tasks/main.yml file for role 'common' must contain a list of tasks

Syntax of roles/common/tasks/main.yml is OK. You can try # ansible-lint roles/common/tasks/main.yml Test the playbook # ansible-lint basic.yml To be sure I'd recommend to remove the sequence of 3 ...
Vladimir Botka's user avatar
2 votes
Accepted

Contents in Kubernetes pod gets empty when persistent volume is mounted

This is expected behaviour: when persistent volume is mounted, it overwrites content of the folder which is specified in mountPath. Therefore you have two options: have content of that directory ...
moonkotte's user avatar
  • 343
2 votes

Alertmanager telegram config chat_id and cannot unmarshal errror

chat_id: -1234567 - without quotes, hyphen isn't a problem And add parse_mode: 'HTML' Parsing markdown is used by default, but in the current version (0.24) many users are seeing problems with this
Bora2k3's user avatar
  • 21
1 vote

SaltStack: found conflicting ID

Don't ask me why, but this works. /etc/sudoers.d/foo: file.managed: - contents: | foo ALL = NOPASSWD: /usr/bin/systemctl restart minio_storage-foo.service foo ALL = NOPASSWD: /bin/...
guettli's user avatar
  • 3,923
1 vote

Unable to delete daemonSet in k8s

I realised that one of my nodes were 'not ready' because one of the K8s services was crushed so first I had to reload the crushed service and then my node back to ready state so later I got the ...
Lidor Ettinger's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible