This commit is contained in:
Alex 2023-11-08 17:37:18 +00:00
parent a3ce91dc9d
commit 8eaabf9544
4 changed files with 49 additions and 0 deletions

View File

@ -15,6 +15,7 @@ inventory = inventory.ini
remote_user = user-ansible
host_key_checking = false
vault_password_file = /root/ansible/vault.key
#callbacks_enabled = timer, profile_roles, profile_tasks
[privilege_escalation]
become = True

8
assert_filter.yaml Normal file
View File

@ -0,0 +1,8 @@
---
- name: demonstrate filters
hosts: localhost
tasks:
- name: manipulate a list and check
assert:
that:
- "{{ [ 2, 3, 1, 2, 4, 2 ] | sort | unique | list }} is eq( [ 1, 2, 3, 4 ] )"

29
filemap.yaml Normal file
View File

@ -0,0 +1,29 @@
---
- name: showing map
hosts: all
gather_facts: no
become: yes
vars:
- basedir: /var/www/html
tasks:
- name: showing basedir
debug:
var: basedir
- name: showing files in basedir
find:
paths: "{{ basedir }}"
recurse: yes
register: basedir_files
- name: showing current variable contents to understand why we need map
debug:
var: basedir_files
- name: show files based on map attribute path without list - will show error
set_fact:
webfiles: "{{ basedir_files['files'] | map(attribute='path') }}"
- debug:
var: webfiles
- name: show files based on map attribute with list
set_fact:
webfileslist: "{{ basedir_files['files'] | map(attribute='path') | list }}"
- debug:
var: webfileslist

11
plugin-lines.yml Normal file
View File

@ -0,0 +1,11 @@
---
- name: checking out lines and pipes lookup plugins
hosts: localhost
gather_facts: no
tasks:
- name: print the first line of any file
debug:
msg: "{{ item[0] }}"
loop:
- "{{ query('lines', 'cat /etc/hosts') }}"
- "{{ query('lines', 'cat /etc/passwd') }}"