feat: add example of test plugin (for collection)

This commit is contained in:
Dany LE 2025-04-11 14:19:26 +00:00
parent 0e2ea0b968
commit ddcb6b2d2d
10 changed files with 86 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__

View File

@ -15,7 +15,7 @@ inventory = inventory.ini
remote_user = user-ansible
host_key_checking = false
vault_password_file = /root/workspace/ansible-practice/vault.key
#callbacks_enabled = timer, profile_roles, profile_tasks
callbacks_enabled = timer, profile_roles, profile_tasks
log_path=/tmp/ansible_log.txt
collections_paths=/root/workspace/ansible-practice/projet00/collections

9
plugins/log-playbook.yml Normal file
View File

@ -0,0 +1,9 @@
- name: Exemple log dans un fichier
hosts: localhost
gather_facts: no
tasks:
- name: Test de ping
ping:
- name: Message de test
debug:
msg: "Ce message sera loggé dans le fichier"

View File

@ -0,0 +1,8 @@
- name: Test blue
hosts: localhost
vars:
my_color_choice: "#00f"
tasks:
- name: "Verify {{ my_color_choice }} is a form of blue."
assert:
that: my_color_choice is blue

10
plugins/plugin-lines.yml Normal file
View File

@ -0,0 +1,10 @@
- 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') }}"

View File

@ -0,0 +1,17 @@
def is_blue(string):
blue_values = [
'blue',
'#0000ff',
'#00f',
'rgb(0,0,255)',
'rgb(0%,0%,100%)',
]
if string in blue_values:
return True
else:
return False
class TestModule(object):
''' Ansible core blue test '''
def tests(self):
return {'blue': is_blue}

View File

@ -0,0 +1,17 @@
def is_blue(string):
blue_values = [
'blue',
'#0000ff',
'#00f',
'rgb(0,0,255)',
'rgb(0%,0%,100%)',
]
if string in blue_values:
return True
else:
return False
class TestModule(object):
''' Ansible core blue test '''
def tests(self):
return {'blue': is_blue}

View File

@ -3,3 +3,6 @@
- name: Debug test
ansible.builtin.debug:
msg: "Un role test !!!"
- name: "Verify {{ my_color_choice }} is a form of blue."
ansible.builtin.assert:
that: my_color_choice is coll.test.blue

View File

@ -5,3 +5,5 @@
tasks:
- ansible.builtin.import_role:
name: coll.test.rtest
vars:
my_color_choice: blue

View File

@ -0,0 +1,17 @@
- name: Test du module personnalisé second_module
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Utiliser second_module pour dire bonjour
coll.test.my_module:
name: Dany LE
path: /tmp/bonjour_ansible-3.txt
register: result
- name: Afficher le message du module
debug:
msg: "{{ result.message }}"
- name: Afficher le diff (si présent)
debug:
var: result.diff
when: result.diff is defined