diff options
author | Jasper Ras <jras@hostnet.nl> | 2025-01-19 21:14:51 +0100 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2025-01-19 21:14:51 +0100 |
commit | 9642cd7ae24f0ba79ce5647c709b35ae8f06a285 (patch) | |
tree | ae25c3b0db7ae4c23186b294c6d000073f085c2d /3 resources/ansible | |
parent | 969b96c2531fb986f6c7f21fd544391b439defd7 (diff) |
vault backup: 2025-01-19 21:14:51
Diffstat (limited to '3 resources/ansible')
-rw-r--r-- | 3 resources/ansible/ad-hoc-commands.md | 25 | ||||
-rw-r--r-- | 3 resources/ansible/ansible.md | 1 | ||||
-rw-r--r-- | 3 resources/ansible/build-array-loop.md | 6 | ||||
-rw-r--r-- | 3 resources/ansible/build-list-silences.md | 1 | ||||
-rw-r--r-- | 3 resources/ansible/debug.md | 29 | ||||
-rw-r--r-- | 3 resources/ansible/default-filter.md | 7 | ||||
-rw-r--r-- | 3 resources/ansible/delegate-to.md | 3 | ||||
-rw-r--r-- | 3 resources/ansible/dicts.md | 1 | ||||
-rw-r--r-- | 3 resources/ansible/extra-vars.md | 8 | ||||
-rw-r--r-- | 3 resources/ansible/find.md | 9 | ||||
-rw-r--r-- | 3 resources/ansible/loop-output.md | 1 | ||||
-rw-r--r-- | 3 resources/ansible/loop-register.md | 41 | ||||
-rw-r--r-- | 3 resources/ansible/loop-results-prior-loop.md | 30 | ||||
-rw-r--r-- | 3 resources/ansible/nested-loops.md | 3 | ||||
-rw-r--r-- | 3 resources/ansible/set-facts.md | 1 |
15 files changed, 0 insertions, 166 deletions
diff --git a/3 resources/ansible/ad-hoc-commands.md b/3 resources/ansible/ad-hoc-commands.md deleted file mode 100644 index eda1265..0000000 --- a/3 resources/ansible/ad-hoc-commands.md +++ /dev/null @@ -1,25 +0,0 @@ -Using ansible we can perform ad-hoc commands, useful for a one-off thing that won't require writing a full playbook. - -Some examples include: -update apt cache: -``` -ansible <pattern> -m ansible.builtin.apt -a "update_cache=true cache_valid_time=3600" -``` - -update packages: -``` -ansible <pattern> -m ansible.builtin.apt -a "name=* state=latest" -``` - -run puppet: -``` -ansible <pattern> -a "/opt/puppetlabs/bin/puppet agent --test" -``` - -reboot: -``` -ansible <pattern> -m ansible.builtin.reboot -f 1 -``` - -[[ansible]] -#ansible
\ No newline at end of file diff --git a/3 resources/ansible/ansible.md b/3 resources/ansible/ansible.md deleted file mode 100644 index 5886288..0000000 --- a/3 resources/ansible/ansible.md +++ /dev/null @@ -1 +0,0 @@ -At its heart it's just an abstraction over running commands remotely over SSH. It enables some powerful automation like setting up a server following a predetermined script.
\ No newline at end of file diff --git a/3 resources/ansible/build-array-loop.md b/3 resources/ansible/build-array-loop.md deleted file mode 100644 index 15f441f..0000000 --- a/3 resources/ansible/build-array-loop.md +++ /dev/null @@ -1,6 +0,0 @@ -How to construct an array variable containing results of an iterative ansible task? -Use register. The referenced variable will contain a property results which is a list containing the combined outputs of the loop. - -https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html#registering-variables-with-a-loop - -[[ansible]]
\ No newline at end of file diff --git a/3 resources/ansible/build-list-silences.md b/3 resources/ansible/build-list-silences.md deleted file mode 100644 index dc8ef61..0000000 --- a/3 resources/ansible/build-list-silences.md +++ /dev/null @@ -1 +0,0 @@ -Explain what I did today at work to build a list of silences and then have one task to unsilence all of them.
\ No newline at end of file diff --git a/3 resources/ansible/debug.md b/3 resources/ansible/debug.md deleted file mode 100644 index 552af1f..0000000 --- a/3 resources/ansible/debug.md +++ /dev/null @@ -1,29 +0,0 @@ -``` -- name: Print the gateway for each host when defined - ansible.builtin.debug: - msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }} - when: ansible_default_ipv4.gateway is defined - -- name: Get uptime information - ansible.builtin.shell: /usr/bin/uptime - register: result - -- name: Print return information from the previous task - ansible.builtin.debug: - var: result - verbosity: 2 - -- name: Display all variables/facts known for a host - ansible.builtin.debug: - var: hostvars[inventory_hostname] - verbosity: 4 - -- name: Prints two lines of messages, but only if there is an environment value set - ansible.builtin.debug: - msg: - - "Provisioning based on YOUR_KEY which is: {{ lookup('ansible.builtin.env', 'YOUR_KEY') }}" - - "These servers were built using the password of '{{ password_used }}'. Please retain this for later use." -``` - ---- -https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
\ No newline at end of file diff --git a/3 resources/ansible/default-filter.md b/3 resources/ansible/default-filter.md deleted file mode 100644 index 2255e71..0000000 --- a/3 resources/ansible/default-filter.md +++ /dev/null @@ -1,7 +0,0 @@ -Using the default filter, if we reference an undefined variable we can set a default: `{{ var | default([]) }}`. - -defaults: -- int -- str -- list ([]) -- dict ({})
\ No newline at end of file diff --git a/3 resources/ansible/delegate-to.md b/3 resources/ansible/delegate-to.md deleted file mode 100644 index 270ccb1..0000000 --- a/3 resources/ansible/delegate-to.md +++ /dev/null @@ -1,3 +0,0 @@ -Through the use of delegate to, we can run a task for certain nodes and delegate work on behalf of those nodes to other hosts. - -A great example of usage is this: diff --git a/3 resources/ansible/dicts.md b/3 resources/ansible/dicts.md deleted file mode 100644 index eac3d1b..0000000 --- a/3 resources/ansible/dicts.md +++ /dev/null @@ -1 +0,0 @@ -Merged using combine: `{{ dict1 | ansible.builtin.combine(dict2) }}`
\ No newline at end of file diff --git a/3 resources/ansible/extra-vars.md b/3 resources/ansible/extra-vars.md deleted file mode 100644 index 07b0764..0000000 --- a/3 resources/ansible/extra-vars.md +++ /dev/null @@ -1,8 +0,0 @@ -We can pass variables to the ansible upon invoking it using `--extra-vars` or `-e`. - -``` ---extra-vars "blaat=piet henk=joop" ---extra-vars '{"blaat":"piet","henk":"joop"}' ---extra-vars "@file.json" ---extra-vars "@file.yml" -``` diff --git a/3 resources/ansible/find.md b/3 resources/ansible/find.md deleted file mode 100644 index 1f4de51..0000000 --- a/3 resources/ansible/find.md +++ /dev/null @@ -1,9 +0,0 @@ -``` -- name: Find file with size >= 50G - ansible.builtin.find: - paths: - - /var/lib/nova/instances/_base - size: 50g -``` ---- -https://docs.ansible.com/ansible/latest/collections/ansible/builtin/find_module.html
\ No newline at end of file diff --git a/3 resources/ansible/loop-output.md b/3 resources/ansible/loop-output.md deleted file mode 100644 index 30a0848..0000000 --- a/3 resources/ansible/loop-output.md +++ /dev/null @@ -1 +0,0 @@ -Using the label field we can select what to print, instead of the whole item.
\ No newline at end of file diff --git a/3 resources/ansible/loop-register.md b/3 resources/ansible/loop-register.md deleted file mode 100644 index bab52a5..0000000 --- a/3 resources/ansible/loop-register.md +++ /dev/null @@ -1,41 +0,0 @@ -When using a loop the registered variable will contain the results of all the responses: -```JSON -{ - "changed": true, - "msg": "All items completed", - "results": [ - { - "changed": true, - "cmd": "echo \"one\" ", - "delta": "0:00:00.003110", - "end": "2013-12-19 12:00:05.187153", - "invocation": { - "module_args": "echo \"one\"", - "module_name": "shell" - }, - "item": "one", - "rc": 0, - "start": "2013-12-19 12:00:05.184043", - "stderr": "", - "stdout": "one" - }, - { - "changed": true, - "cmd": "echo \"two\" ", - "delta": "0:00:00.002920", - "end": "2013-12-19 12:00:05.245502", - "invocation": { - "module_args": "echo \"two\"", - "module_name": "shell" - }, - "item": "two", - "rc": 0, - "start": "2013-12-19 12:00:05.242582", - "stderr": "", - "stdout": "two" - } - ] -} -``` - -Thus we can loop over each results `{{ registered_var.results }}`.
\ No newline at end of file diff --git a/3 resources/ansible/loop-results-prior-loop.md b/3 resources/ansible/loop-results-prior-loop.md deleted file mode 100644 index cbd50a2..0000000 --- a/3 resources/ansible/loop-results-prior-loop.md +++ /dev/null @@ -1,30 +0,0 @@ -```YAML -- name: First loop - loop: {{ blaat }} - register: loooped - ... - -- name: Second loop - loop: {{ loooped.results }} - when: item.skipped is not defined -``` - -this loops over results of prior loop only but does not process any skipped results. - -In case the results array contains another array that we want to loop over, for example when we did a shell command in a loop we can use extract: -``` -- name: Print magic - ansible.builtin.debug: - msg: "{{ ['stdout_lines'] | map('extract', item) }}" - loop: "{{ magic.results }}" -``` - -A cool example of this in practice: -``` -- name: Print blockpull command - ansible.builtin.debug: - msg: "virsh blockpull {{ ['stdout_lines'] | map('extract', item) | list | flatten | join(' ') }}" - loop: "{{ domain_and_disk_paths.results }}" - loop_control: - label: "{{ inventory_hostname }}" -```
\ No newline at end of file diff --git a/3 resources/ansible/nested-loops.md b/3 resources/ansible/nested-loops.md deleted file mode 100644 index fded56a..0000000 --- a/3 resources/ansible/nested-loops.md +++ /dev/null @@ -1,3 +0,0 @@ -Nested loops can be done not by nesting loops over two separate lists, but by looping over the [[Cartesian product]] of the two using the `product` filter. - -`{{ list1 | product(list) | list }}`
\ No newline at end of file diff --git a/3 resources/ansible/set-facts.md b/3 resources/ansible/set-facts.md deleted file mode 100644 index e94eeb6..0000000 --- a/3 resources/ansible/set-facts.md +++ /dev/null @@ -1 +0,0 @@ -These can be used to set and update variables specific to nodes, at runtime.
\ No newline at end of file |