chore(ansible/examples): add the proper ternary operator

This commit is contained in:
Michele Cereda
2024-04-28 21:07:30 +02:00
parent 0576d5926e
commit 3bc2588dc2
9 changed files with 77 additions and 28 deletions

View File

@@ -1,2 +1,3 @@
ansible/playbooks/aws.ec2.enable-ssm-agent.yml package-latest
ansible/playbooks/keybase.register-device.yml no-changed-when
examples/ansible/aws_ec2.yml yaml[comments-indentation]

View File

@@ -29,3 +29,7 @@ indent_size = 4
[*.ts]
indent_size = 4
[Makefile]
indent_style = tab
tab_width = 4

View File

@@ -26,8 +26,9 @@ lint:
parallel: true
commands:
ansible: &ansible-lint
glob: '*ansible*'
run: .venv/bin/ansible-lint
files: find . -type f -path "*ansible*" -not -path "*venv*"
glob: '*.{yaml,yml}'
run: .venv/bin/ansible-lint {files}
docker: &hadolint
# The official docker image is based on scratch and only takes only one
# input file at a time. I have no clue how to fix that for now so let's

View File

@@ -5,8 +5,12 @@ override venv ?= ${shell git rev-parse --show-toplevel}/.venv
create-venv: override python_version ?= 3.12
create-venv: ${shell which 'python${python_version}'}
@python${python_version} -m 'venv' '${venv}'
@source '${venv}/bin/activate' && pip --require-virtualenv install -r 'requirements.txt'
@${venv}/bin/pip --require-virtualenv install -U -r 'requirements.txt'
recreate-venv:
@rm -r '${venv}'
@${MAKE} create-venv
update-venv: ${venv}/bin/pip
@${venv}/bin/pip freeze -l --require-virtualenv | sed 's/==/>=/' \
| xargs ${venv}/bin/pip --require-virtualenv install -U

View File

@@ -99,7 +99,9 @@
minute: 0
hour: 3 # 3 AM
weekday: 0 # Sunday
job: docker ps -f 'name=pihole' -f 'status=running' -f 'health=healthy' -q | xargs -I{} docker exec {} pihole -g
job: >-
docker ps -f 'name=pihole' -f 'status=running' -f 'health=healthy' -q
| xargs -I{} docker exec {} pihole -g
- name: Create the cron job for automatic backups
tags:
- backup
@@ -119,9 +121,10 @@
- graviton
community.docker.docker_container_exec:
container: pihole
command: >
command: >-
sqlite3 '/etc/pihole/gravity.db'
"INSERT OR IGNORE INTO adlist (address, enabled, comment) VALUES ('{{ item }}', 1, 'Listed on v.firebog.net');"
"INSERT OR IGNORE INTO adlist (address, enabled, comment)
VALUES ('{{ item }}', 1, 'Listed on v.firebog.net');"
# on M1 macs execute `export NO_PROXY=*` first
loop: "{{ lookup('ansible.builtin.url', 'https://v.firebog.net/hosts/lists.php?type=tick', wantlist=True) }}"
async: 600

View File

@@ -11,6 +11,24 @@
- name: Get back a conditional value.
ansible.builtin.debug:
var: "{{ 'true' if 'test me a lot' is match('test') else 'false' }}"
- name: Use the ternary operator.
ansible.builtin.debug:
msg: >-
{{
'test me a lot' is match('test')
| ternary(
'what_if_true',
'what_if_false'
)
}}
{{
'test me a lot' is match('test')
| ternary(
'what_if_true',
'what_if_false',
'what_if_null'
)
}}
# Returns ["string"] from ["", "string", 0, false].
- name: Remove empty or false values from a list piping it to 'select()'.
@@ -118,6 +136,19 @@
- "{{ resource_url is search('USERS', ignorecase=true) }}"
- "{{ resource_url is regex('example\\.com/\\w+/foo') }}"
- name: Get specific lines from walls of text.
ansible.builtin.debug:
msg: "{{ previous_task.stdout | regex_findall('Infra Phase complete, .*') }}"
- name: Test specific lines from walls of text.
ansible.builtin.debug:
msg: >-
{{
(
previous_task.stdout
| regex_findall('Infra Phase complete, .*')
) is not search('0/')
}}"
- name: Show off Ansible's loops
hosts: all
tasks:

View File

@@ -15,7 +15,8 @@
## Configuration
The configuration consists of the application's defaults, overridden by the user settings first and, if existing, by the workspace settings.<br/>
The configuration consists of the application's defaults, overridden by the user settings first and, if existing, by the
workspace settings.<br/>
See the [settings.json] example.
The user configuration is loaded from the `settings.json` file in the user's configuration directory for the application.
@@ -44,7 +45,7 @@ Built-in:
Extensions:
| Extension | Setting | Default value | Scopes | Location in tree | Description |
| -------------------------- | --------------------------------------------- | ------------- | --------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| -------------------------- | --------------------------------------------- | ------------- | --------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| vscode.git (built-in) | `git.autofetch` | `true` | User, Workspace | Extensions > Git | When set to true, commits will automatically be fetched from the default remote of the current Git repository. Setting to `all` will fetch from all remotes. |
| angelo-breuer.clock | `clock.alignment` | `"Left"` | User, Workspace | Extensions > Status Bar Clock | Alignment of the clock on the status bar. |
| angelo-breuer.clock | `clock.format` | `"hh:MM"` | User, Workspace | Extensions > Status Bar Clock | Date and time format. See <https://www.npmjs.com/package/dateformat#mask-options> for more options. |
@@ -52,7 +53,8 @@ Extensions:
| yzhang.markdown-all-in-one | `markdown.extension.orderedList.marker` | `"ordered"` | User, Workspace | Extensions > Markdown All In One | Auto fix ordered list markers. |
| yzhang.markdown-all-in-one | `markdown.extension.toc.levels` | `"1..6"` | User, Workspace | Extensions > Markdown All In One | Range of levels for the ToC. |
| yzhang.markdown-all-in-one | `markdown.extension.toc.orderedList` | `false` | User, Workspace | Extensions > Markdown All In One | Use an ordered list in the ToC. |
| redhat.ansible | `redhat.telemetry.enabled` | `true` | User, Workspace | Extensions > Ansible | Send telemetry to Red Hat servers. |
| redhat.ansible | `redhat.telemetry.enabled` | `true` | User, Workspace | Extensions > Ansible > Telemetry | Send telemetry to Red Hat servers. |
| redhat.ansible | `ansible.validation.lint.enabled` | `true` | User, Workspace | Extensions > Ansible > Validation | USe ansible-lint if found to lint Ansible files. Kinda a nuisance when enabled. |
## Handy keyboard shortcuts
@@ -140,7 +142,7 @@ sudo dscl . append '/Groups/_developer' GroupMembership "$USER"
- [Documentation]
- [Network connections in Visual Studio Code]
## Sources
### Sources
- [Using extensions in compiled VSCode]
- [Recommending VSCode extensions within your Open Source projects]
@@ -148,6 +150,7 @@ sudo dscl . append '/Groups/_developer' GroupMembership "$USER"
- [VSCode (and some non-patched Electron applications) doesn't run after Tumbleweed update on Nvidia]
- [Electron applications all crash upon launch]
- [Authorize a non-admin developer in Xcode / Mac OS]
- [Deep dive on Ansible VScode extension]
<!--
References
@@ -164,6 +167,7 @@ sudo dscl . append '/Groups/_developer' GroupMembership "$USER"
<!-- Others -->
[authorize a non-admin developer in xcode / mac os]: https://stackoverflow.com/questions/1837889/authorize-a-non-admin-developer-in-xcode-mac-os#1837935
[deep dive on ansible vscode extension]: https://www.ansible.com/blog/deep-dive-on-ansible-vscode-extension/
[electron applications all crash upon launch]: https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1944468
[recommending vscode extensions within your open source projects]: https://tattoocoder.com/recommending-vscode-extensions-within-your-open-source-projects/
[using extensions in compiled vscode]: https://stackoverflow.com/questions/44057402/using-extensions-in-compiled-vscode#45291490

View File

@@ -1,3 +1,4 @@
ansible==9.4.0
ansible==9.5.1
ansible-lint==24.2.2
click==8.1.7
pyinilint==0.17