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/aws.ec2.enable-ssm-agent.yml package-latest
ansible/playbooks/keybase.register-device.yml no-changed-when 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] [*.ts]
indent_size = 4 indent_size = 4
[Makefile]
indent_style = tab
tab_width = 4

View File

@@ -26,8 +26,9 @@ lint:
parallel: true parallel: true
commands: commands:
ansible: &ansible-lint ansible: &ansible-lint
glob: '*ansible*' files: find . -type f -path "*ansible*" -not -path "*venv*"
run: .venv/bin/ansible-lint glob: '*.{yaml,yml}'
run: .venv/bin/ansible-lint {files}
docker: &hadolint docker: &hadolint
# The official docker image is based on scratch and only takes only one # 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 # 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: override python_version ?= 3.12
create-venv: ${shell which 'python${python_version}'} create-venv: ${shell which 'python${python_version}'}
@python${python_version} -m 'venv' '${venv}' @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: recreate-venv:
@rm -r '${venv}' @rm -r '${venv}'
@${MAKE} create-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

@@ -37,15 +37,15 @@
dest: /etc/knockd.conf dest: /etc/knockd.conf
content: | content: |
[options] [options]
UseSyslog UseSyslog
Interface = {{ ansible_default_ipv4.alias }} Interface = {{ ansible_default_ipv4.alias }}
[openClose7777] [openClose7777]
sequence = 2222:udp,3333:tcp,4444:udp sequence = 2222:udp,3333:tcp,4444:udp
seq_timeout = 15 seq_timeout = 15
tcpflags = syn tcpflags = syn
cmd_timeout = 10 cmd_timeout = 10
start_command = /usr/bin/firewall-cmd --add-port=7777/tcp --zone=public start_command = /usr/bin/firewall-cmd --add-port=7777/tcp --zone=public
stop_command = /usr/bin/firewall-cmd --remove-port=7777/tcp --zone=public stop_command = /usr/bin/firewall-cmd --remove-port=7777/tcp --zone=public
backup: true backup: true
mode: '0600' mode: '0600'

View File

@@ -99,7 +99,9 @@
minute: 0 minute: 0
hour: 3 # 3 AM hour: 3 # 3 AM
weekday: 0 # Sunday 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 - name: Create the cron job for automatic backups
tags: tags:
- backup - backup
@@ -119,9 +121,10 @@
- graviton - graviton
community.docker.docker_container_exec: community.docker.docker_container_exec:
container: pihole container: pihole
command: > command: >-
sqlite3 '/etc/pihole/gravity.db' 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 # on M1 macs execute `export NO_PROXY=*` first
loop: "{{ lookup('ansible.builtin.url', 'https://v.firebog.net/hosts/lists.php?type=tick', wantlist=True) }}" loop: "{{ lookup('ansible.builtin.url', 'https://v.firebog.net/hosts/lists.php?type=tick', wantlist=True) }}"
async: 600 async: 600

View File

@@ -11,6 +11,24 @@
- name: Get back a conditional value. - name: Get back a conditional value.
ansible.builtin.debug: ansible.builtin.debug:
var: "{{ 'true' if 'test me a lot' is match('test') else 'false' }}" 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]. # Returns ["string"] from ["", "string", 0, false].
- name: Remove empty or false values from a list piping it to 'select()'. - 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 search('USERS', ignorecase=true) }}"
- "{{ resource_url is regex('example\\.com/\\w+/foo') }}" - "{{ 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 - name: Show off Ansible's loops
hosts: all hosts: all
tasks: tasks:

View File

@@ -11,11 +11,12 @@
1. [_No extensions found_ when running from source](#no-extensions-found-when-running-from-source) 1. [_No extensions found_ when running from source](#no-extensions-found-when-running-from-source)
1. [_Type the name and password of a user in the 'Developer Tools' group to allow Developer Tools Access to make changes_ on Mac OS X](#type-the-name-and-password-of-a-user-in-the-developer-tools-group-to-allow-developer-tools-access-to-make-changes-on-mac-os-x) 1. [_Type the name and password of a user in the 'Developer Tools' group to allow Developer Tools Access to make changes_ on Mac OS X](#type-the-name-and-password-of-a-user-in-the-developer-tools-group-to-allow-developer-tools-access-to-make-changes-on-mac-os-x)
1. [Further readings](#further-readings) 1. [Further readings](#further-readings)
1. [Sources](#sources) 1. [Sources](#sources)
## Configuration ## 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. See the [settings.json] example.
The user configuration is loaded from the `settings.json` file in the user's configuration directory for the application. The user configuration is loaded from the `settings.json` file in the user's configuration directory for the application.
@@ -43,16 +44,17 @@ Built-in:
Extensions: Extensions:
| Extension | Setting | Default value | Scopes | Location in tree | Description | | 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. | | 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.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. | | 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. |
| yzhang.markdown-all-in-one | `markdown.extension.orderedList.autoRenumber` | `true` | User, Workspace | Extensions > Markdown All In One | Auto fix ordered list markers. | | yzhang.markdown-all-in-one | `markdown.extension.orderedList.autoRenumber` | `true` | User, Workspace | Extensions > Markdown All In One | Auto fix ordered list markers. |
| 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.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.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. | | 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 ## Handy keyboard shortcuts
@@ -140,7 +142,7 @@ sudo dscl . append '/Groups/_developer' GroupMembership "$USER"
- [Documentation] - [Documentation]
- [Network connections in Visual Studio Code] - [Network connections in Visual Studio Code]
## Sources ### Sources
- [Using extensions in compiled VSCode] - [Using extensions in compiled VSCode]
- [Recommending VSCode extensions within your Open Source projects] - [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] - [VSCode (and some non-patched Electron applications) doesn't run after Tumbleweed update on Nvidia]
- [Electron applications all crash upon launch] - [Electron applications all crash upon launch]
- [Authorize a non-admin developer in Xcode / Mac OS] - [Authorize a non-admin developer in Xcode / Mac OS]
- [Deep dive on Ansible VScode extension]
<!-- <!--
References References
@@ -164,6 +167,7 @@ sudo dscl . append '/Groups/_developer' GroupMembership "$USER"
<!-- Others --> <!-- 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 [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 [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/ [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 [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 click==8.1.7
pyinilint==0.17 pyinilint==0.17