chore(ansible): add snippets

This commit is contained in:
Michele Cereda
2025-08-25 23:05:42 +02:00
parent 825575ff47
commit e460a4c988
3 changed files with 38 additions and 8 deletions

View File

@@ -1760,6 +1760,7 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
- [How to run Ansible with_fileglob in alphabetical order?] - [How to run Ansible with_fileglob in alphabetical order?]
- [Ansible v2.14 CHANGELOG] - [Ansible v2.14 CHANGELOG]
- [How can I pass variable to ansible playbook in the command line?] - [How can I pass variable to ansible playbook in the command line?]
- [Ansible Map Examples - Filter List and Dictionaries]
<!-- <!--
Reference Reference
@@ -1815,6 +1816,7 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
<!-- Others --> <!-- Others -->
[6 ways to speed up ansible playbook execution]: https://wearenotch.com/speed-up-ansible-playbook-execution/ [6 ways to speed up ansible playbook execution]: https://wearenotch.com/speed-up-ansible-playbook-execution/
[ansible - how to remove an item from a list?]: https://stackoverflow.com/questions/40927792/ansible-how-to-remove-an-item-from-a-list#40927834 [ansible - how to remove an item from a list?]: https://stackoverflow.com/questions/40927792/ansible-how-to-remove-an-item-from-a-list#40927834
[Ansible Map Examples - Filter List and Dictionaries]: https://www.middlewareinventory.com/blog/ansible-map/
[ansible roles: basics, creating & using]: https://spacelift.io/blog/ansible-roles [ansible roles: basics, creating & using]: https://spacelift.io/blog/ansible-roles
[ansible vault tutorial]: https://piyops.com/ansible-vault-tutorial [ansible vault tutorial]: https://piyops.com/ansible-vault-tutorial
[ansible vault with awx]: https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/ansible-vault-with-awx-80b603617798 [ansible vault with awx]: https://medium.com/t%C3%BCrk-telekom-bulut-teknolojileri/ansible-vault-with-awx-80b603617798
@@ -1824,6 +1826,7 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
[Easy things you can do to speed up ansible]: https://mayeu.me/post/easy-things-you-can-do-to-speed-up-ansible/ [Easy things you can do to speed up ansible]: https://mayeu.me/post/easy-things-you-can-do-to-speed-up-ansible/
[edit .ini file in other servers using ansible playbook]: https://syslint.com/blog/tutorial/edit-ini-file-in-other-servers-using-ansible-playbook/ [edit .ini file in other servers using ansible playbook]: https://syslint.com/blog/tutorial/edit-ini-file-in-other-servers-using-ansible-playbook/
[Handling secrets in your Ansible playbooks]: https://www.redhat.com/sysadmin/ansible-playbooks-secrets [Handling secrets in your Ansible playbooks]: https://www.redhat.com/sysadmin/ansible-playbooks-secrets
[Hide sensitive data in Ansible verbose logs]: https://harshanu.space/en/tech/ansible-redact/
[how can i hide skipped tasks output in ansible]: https://stackoverflow.com/questions/39189549/how-can-i-hide-skipped-tasks-output-in-ansible#76147924 [how can i hide skipped tasks output in ansible]: https://stackoverflow.com/questions/39189549/how-can-i-hide-skipped-tasks-output-in-ansible#76147924
[how can i pass variable to ansible playbook in the command line?]: https://stackoverflow.com/questions/30662069/how-can-i-pass-variable-to-ansible-playbook-in-the-command-line#30662156 [how can i pass variable to ansible playbook in the command line?]: https://stackoverflow.com/questions/30662069/how-can-i-pass-variable-to-ansible-playbook-in-the-command-line#30662156
[how to append to lists]: https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible [how to append to lists]: https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible
@@ -1853,4 +1856,3 @@ Another _better (?)_ solution in playbooks/roles would be to sanitize the input
[working with versions]: https://docs.ansible.com/ansible/latest/collections/community/general/docsite/filter_guide_working_with_versions.html [working with versions]: https://docs.ansible.com/ansible/latest/collections/community/general/docsite/filter_guide_working_with_versions.html
[yes and no, true and false]: https://chronicler.tech/red-hat-ansible-yes-no-and/ [yes and no, true and false]: https://chronicler.tech/red-hat-ansible-yes-no-and/
[zuul]: https://zuul-ci.org/ [zuul]: https://zuul-ci.org/
[Hide sensitive data in Ansible verbose logs]: https://harshanu.space/en/tech/ansible-redact/

View File

@@ -628,16 +628,34 @@
seconds: 60 seconds: 60
- name: EC2-specific operations - name: EC2-specific operations
# Notice: tasks using the 'ec2_instance' module might create a new instance even if older ones exist from a # Notice: tasks using the 'ec2_instance' module might create a new instance even if older ones exist from a
# different run, but return the *old* instance's ID and information. # different run, but return the *old* instance's ID and information.
# This seems to be an issue with how the module filters EC2 instances out when deciding whether existing # This seems to be an issue with how the module filters EC2 instances out when deciding whether existing
# instances match and should be altered. By default, instances are filtered by 'Name' tag, base AMI, state, and # instances match and should be altered. By default, instances are filtered by 'Name' tag, base AMI, state, and
# subnet ID. Refer the module's 'filters' property. # subnet ID. Refer the module's 'filters' property.
# `filters` accepts inputs as the API would. Refer
# <https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html>
# ALERT: `filters` takes precedence over `instance_ids` - do *not* do something like
# amazon.aws.ec2_instance:
# instance_ids: i-0123456789abcdef0
# filters:
# instance-state-name: running
# state: terminated
# as it will terminate *all* running instances, not only the specified instance *if* running.
# The AWS API, instead, work as expected as of 2025-08-25.
block: block:
- name: Get running instances with 'K8S' as the 'Application' tag - name: Get information about running instances with 'K8S' as the 'Application' tag
amazon.aws.ec2_instance_info: amazon.aws.ec2_instance_info:
filters: filters:
"tag:Application": K8S tag:Application: K8S
instance-state-name: ["running"] instance-state-name: ["running"]
- name: Start stopped PG dumper instances
tags: dumper
amazon.aws.ec2_instance:
filters:
instance-state-name: stopped
tag:Application: Postgres
tag:Component: Dumper
state: started
- name: Clone EC2 instances - name: Clone EC2 instances
vars: vars:
source_instance_id: i-0123456789abcdef0 source_instance_id: i-0123456789abcdef0
@@ -869,10 +887,11 @@
ansible_remote_tmp: /tmp/.ansible-ssm-user/tmp ansible_remote_tmp: /tmp/.ansible-ssm-user/tmp
ansible_async_dir: /tmp/.ansible-ssm-user/async ansible_async_dir: /tmp/.ansible-ssm-user/async
tasks: tasks:
- name: Start the PG dumper instance - name: Start stopped PG dumper instances
tags: dumper tags: dumper
amazon.aws.ec2_instance: amazon.aws.ec2_instance:
filters: filters:
instance-state-name: stopped
tag:Application: Postgres tag:Application: Postgres
tag:Component: Dumper tag:Component: Dumper
state: started state: started

View File

@@ -296,6 +296,15 @@
{{ 'ansible_job_id' | extract(module_output | regex_search('{.*}') | from_json) }} {{ 'ansible_job_id' | extract(module_output | regex_search('{.*}') | from_json) }}
base64_encoded_string: "{{ 'some string' | ansible.builtin.b64encode }}" base64_encoded_string: "{{ 'some string' | ansible.builtin.b64encode }}"
base64_decoded_string: "{{ 'c29tZSBzdHJpbmc=' | ansible.builtin.b64decode }}" base64_decoded_string: "{{ 'c29tZSBzdHJpbmc=' | ansible.builtin.b64decode }}"
csv_to_command_options: >-
{{
[
pg_shared_preload_libraries|split(',')|reject('equalto','pgaudit')|map('regex_replace','^','--extension='),
'--no-publications',
'--no-subscriptions',
'--exclude-schema=transient_views',
] | flatten | unique
}}
- name: Return data types - name: Return data types
tags: tags: