feat: add example of test plugin (for collection)
This commit is contained in:
parent
0e2ea0b968
commit
ddcb6b2d2d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__
|
@ -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
9
plugins/log-playbook.yml
Normal 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"
|
8
plugins/playbook-blue.yml
Normal file
8
plugins/playbook-blue.yml
Normal 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
10
plugins/plugin-lines.yml
Normal 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') }}"
|
17
plugins/test_plugins/blue.py
Normal file
17
plugins/test_plugins/blue.py
Normal 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}
|
@ -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}
|
@ -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
|
@ -5,3 +5,5 @@
|
||||
tasks:
|
||||
- ansible.builtin.import_role:
|
||||
name: coll.test.rtest
|
||||
vars:
|
||||
my_color_choice: blue
|
17
projet00/test-collection-module.yml
Normal file
17
projet00/test-collection-module.yml
Normal 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
|
Loading…
x
Reference in New Issue
Block a user