diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bee8a64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ diff --git a/ansible.cfg b/ansible.cfg index ad88240..d0ba943 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -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 diff --git a/plugins/log-playbook.yml b/plugins/log-playbook.yml new file mode 100644 index 0000000..f2d759f --- /dev/null +++ b/plugins/log-playbook.yml @@ -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" \ No newline at end of file diff --git a/plugins/playbook-blue.yml b/plugins/playbook-blue.yml new file mode 100644 index 0000000..a773dc8 --- /dev/null +++ b/plugins/playbook-blue.yml @@ -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 \ No newline at end of file diff --git a/plugins/plugin-lines.yml b/plugins/plugin-lines.yml new file mode 100644 index 0000000..503e9a7 --- /dev/null +++ b/plugins/plugin-lines.yml @@ -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') }}" \ No newline at end of file diff --git a/plugins/test_plugins/blue.py b/plugins/test_plugins/blue.py new file mode 100644 index 0000000..6d9015f --- /dev/null +++ b/plugins/test_plugins/blue.py @@ -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} \ No newline at end of file diff --git a/projet00/collections/ansible_collections/coll/test/plugins/test/blue.py b/projet00/collections/ansible_collections/coll/test/plugins/test/blue.py new file mode 100644 index 0000000..6d9015f --- /dev/null +++ b/projet00/collections/ansible_collections/coll/test/plugins/test/blue.py @@ -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} \ No newline at end of file diff --git a/projet00/collections/ansible_collections/coll/test/roles/rtest/tasks/main.yml b/projet00/collections/ansible_collections/coll/test/roles/rtest/tasks/main.yml index e0a0a8b..df507b7 100644 --- a/projet00/collections/ansible_collections/coll/test/roles/rtest/tasks/main.yml +++ b/projet00/collections/ansible_collections/coll/test/roles/rtest/tasks/main.yml @@ -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 \ No newline at end of file diff --git a/projet00/site.yml b/projet00/site.yml index 5b686b2..5219d6d 100644 --- a/projet00/site.yml +++ b/projet00/site.yml @@ -4,4 +4,6 @@ gather_facts: false tasks: - ansible.builtin.import_role: - name: coll.test.rtest \ No newline at end of file + name: coll.test.rtest + vars: + my_color_choice: blue \ No newline at end of file diff --git a/projet00/test-collection-module.yml b/projet00/test-collection-module.yml new file mode 100644 index 0000000..07da3c9 --- /dev/null +++ b/projet00/test-collection-module.yml @@ -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 \ No newline at end of file