diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a3799a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vault_password.txt diff --git a/README.md b/README.md index 8c502b9..cda6a9c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,69 @@ # ansible_update_vm_os_proxmox +** Ne pas utiliser en production sur un ordinateur personnel. Dédier une VM à Ansible sur un hyperviseur sécurisé.** + +Les fichiers de configurations inventory.yml, host_vars/* group_vars/* sont adapter pour VM, vous pouvez en ajouter ou en supprimer + +# Valeurs à replacer et à adapter + +Dans inventory.yml remplacer : + + - ChangeMe-NameVm par le nom de votre vm. (à remplacer également dans les accolades {{ }}) + +Dans le dossier host_vars : + - Renommé ChangeMe-NameVm par le nom de votre vm. + +À l'intérieur des fichier host_vars: + - Remplacer "Changeme-ID"par l'id de votre VM + - remplaer la valeur ChangeMe-NameVm dans {{ vault_ChangeMe-NameVm_root_password }} + +Dans group_vars/vm/proxmox.yml: + - Remplacer ChangeMe-IpOrDnsName + - Adapter ansible@pam par un utilisateur ayant les droits de faire des snapshot et l'audit de vm + - Adapter ansible_snapshot par l'ID de votre token. + +Dans le fichier group_vars/vm/vault.yml: + - Remplacer ChangeMe-NameVm par le nom de votre vm. + - Replacer ChangeMe-user par le nom d'utilisateur utilisé pour le ssh. + - Replacer ChangeMe-password par le mot de passe de l'utilisateur ssh. + - Remplacer ChangeMe-token_secret par le secret du token généré pour l'utilisateur Proxmox + - Remplacer ChangeMe-password_root par le mot de passe root de votre VM. + +Dans le fichier group_vars/vm/variables.yml: + - Remplacer ChangeMe-NameVm0 dans la clé des variables ainsi que dans les accolades {{ vault_ChangeMe-NameVm_user }} + +# Chiffrer le fichier vault.yml + +Dabord, créer le fichier vault_password.txt à la racine du répertoire. Lui donner les droits avec chmod + +``` +chmod 600 vault_password.txt +``` + +Et renseigner le mot de passe pour ansible-vault. + +Puis chiffrer le fichier vault.yml + +``` +ansible-vault encrypt group_vars/vm/vault.yml --encrypt-vault-id default +``` + +## Si vous ne voulez pas utiliser de fichier vault_password.txt + +Retirer dans ansible.cfg : + +vault_password_file = vault_password.txt +vault_identity_list = default@vault_password.txt + +# Installer Ansible dans un venv + +``` +python3 -m venv .venv +source .venv/bin/activate +pip install -r requirements.txt +``` + +# Jouer votre playbook + +``` +ansible-playbook playbook.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..4860613 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,9 @@ +[defaults] +inventory = inventory.yml +vault_password_file = vault_password.txt +vault_identity_list = default@vault_password.txt +ask_pass = False + + +[ssh_connection] +ssh_args = -o PreferredAuthentications=password -o PubkeyAuthentication=no diff --git a/group_vars/vm/proxmox.yml b/group_vars/vm/proxmox.yml new file mode 100644 index 0000000..6a9b5f1 --- /dev/null +++ b/group_vars/vm/proxmox.yml @@ -0,0 +1,7 @@ +proxmox_snapshot_api_host: "ChangeMe-IpOrDnsName" +proxmox_snapshot_api_user: "ansible@pam" +proxmox_snapshot_api_token_id: "ansible_snapshot" +proxmox_snapshot_api_token_secret: "{{ vault_proxmox_snapshot_api_token_secret }}" +proxmox_snapshot_node: "pve" +proxmox_snapshot_vmid: "" +proxmox_snapshot_validate_certs: false diff --git a/group_vars/vm/variables.yml b/group_vars/vm/variables.yml new file mode 100644 index 0000000..ddae370 --- /dev/null +++ b/group_vars/vm/variables.yml @@ -0,0 +1,8 @@ +ChangeMe-NameVm0_user: "{{ vault_ChangeMe-NameVm0_user }}" +ChangeMe-NameVm0_password: "{{ vault_ChangeMe-NameVm0_password }}" +ChangeMe-NameVm1_user: "{{ vault_ChangeMe-NameVm1_user }}" +ChangeMe-NameVm1_password: "{{ vault_ChangeMe-NameVm1_password }}" +ChangeMe-NameVm2_user: "{{ vault_ChangeMe-NameVm2_user }}" +ChangeMe-NameVm2_password: "{{ vault_ChangeMe-NameVm2_password }}" +ChangeMe-NameVm3_user: "{{ vault_ChangeMe-NameVm3_user }}" +ChangeMe-NameVm3_password: "{{ vault_ChangeMe-NameVm3_password }}" diff --git a/group_vars/vm/vault.yml b/group_vars/vm/vault.yml new file mode 100644 index 0000000..d3c4c7b --- /dev/null +++ b/group_vars/vm/vault.yml @@ -0,0 +1,13 @@ +vault_ChangeMe-NameVm0_user: ChangeMe-user +vault_ChangeMe-NameVm0_password: ChangeMe-password +vault_ChangeMe-NameVm1_user: ChangeMe-user +vault_ChangeMe-NameVm1_password: ChangeMe-password +vault_ChangeMe-NameVm2_user: ChangeMe-user +vault_ChangeMe-NameVm3_password: ChangeMe-password +vault_ChangeMe-NameVm3_user: ChangeMe-user +vault_ChangeMe-NameVm3_password: ChangeMe-password +vault_proxmox_snapshot_api_token_secret: "ChangeMe-token_secret" +vault_ChangeMe-NameVm0_root_password: "ChangeMe-password_root" +vault_ChangeMe-NameVm1_root_password: "ChangeMe-password_root" +vault_ChangeMe-NameVm2_root_password: "ChangeMe-password_root" +vault_ChangeMe-NameVm3_root_password: "ChangeMe-password_root" diff --git a/host_vars/ChangeMe-NameVm0.yml b/host_vars/ChangeMe-NameVm0.yml new file mode 100644 index 0000000..6491b2c --- /dev/null +++ b/host_vars/ChangeMe-NameVm0.yml @@ -0,0 +1,6 @@ +proxmox_snapshot_vmid: "ChangeMe-ID" +health_urls: + - https://url.domaine/HealtzPath +ansible_become_user: "root" +ansible_become_password: "{{ vault_ChangeMe-NameVm0_root_password }}" +ansible_become_method: su diff --git a/host_vars/ChangeMe-NameVm1.yml b/host_vars/ChangeMe-NameVm1.yml new file mode 100644 index 0000000..6491b2c --- /dev/null +++ b/host_vars/ChangeMe-NameVm1.yml @@ -0,0 +1,6 @@ +proxmox_snapshot_vmid: "ChangeMe-ID" +health_urls: + - https://url.domaine/HealtzPath +ansible_become_user: "root" +ansible_become_password: "{{ vault_ChangeMe-NameVm0_root_password }}" +ansible_become_method: su diff --git a/host_vars/ChangeMe-NameVm2.yml b/host_vars/ChangeMe-NameVm2.yml new file mode 100644 index 0000000..6491b2c --- /dev/null +++ b/host_vars/ChangeMe-NameVm2.yml @@ -0,0 +1,6 @@ +proxmox_snapshot_vmid: "ChangeMe-ID" +health_urls: + - https://url.domaine/HealtzPath +ansible_become_user: "root" +ansible_become_password: "{{ vault_ChangeMe-NameVm0_root_password }}" +ansible_become_method: su diff --git a/host_vars/ChangeMe-NameVm3.yml b/host_vars/ChangeMe-NameVm3.yml new file mode 100644 index 0000000..6491b2c --- /dev/null +++ b/host_vars/ChangeMe-NameVm3.yml @@ -0,0 +1,6 @@ +proxmox_snapshot_vmid: "ChangeMe-ID" +health_urls: + - https://url.domaine/HealtzPath +ansible_become_user: "root" +ansible_become_password: "{{ vault_ChangeMe-NameVm0_root_password }}" +ansible_become_method: su diff --git a/inventory.yml b/inventory.yml new file mode 100644 index 0000000..2e1035d --- /dev/null +++ b/inventory.yml @@ -0,0 +1,20 @@ +all: + children: + vm: + hosts: + NameVm0: + ansible_host: ip_or_dns_name + ansible_user: "{{ vault_NameVm0_user }}" + ansible_password: "{{ vault_docker_password }}" + NameVm1: + ansible_host: ip_or_dns_name + ansible_user: "{{ vault_NameVm1_user }}" + ansible_password: "{{ vault_gitea_password }}" + NameVm2: + ansible_host: ip_or_dns_name + ansible_user: "{{ vault_NameVm2_user }}" + ansible_password: "{{ vault_drone_password }}" + NameVm3: + ansible_host: ip_or_dns_name + ansible_user: "{{ vault_NameVm3_user }}" + ansible_password: "{{ vault_dokku_password }}" diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..30c01ee --- /dev/null +++ b/playbook.yml @@ -0,0 +1,11 @@ +- hosts: vm + serial: 1 + gather_facts: false + + roles: + - check_healtz + - proxmox_snapshot + - role: update_os + become: true + - check_healtz + - proxmox_snapshot_remove diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f857d0e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +ansible==14.2.0 +ansible-core==2.21.2 +certifi==2026.7.22 +cffi==2.1.0 +charset-normalizer==3.4.9 +cryptography==49.0.0 +idna==3.18 +Jinja2==3.1.6 +MarkupSafe==3.0.3 +packaging==26.2 +proxmoxer==2.3.0 +pycparser==3.0 +PyYAML==6.0.3 +requests==2.34.2 +resolvelib==1.2.1 +urllib3==2.7.0 diff --git a/roles/check_healtz/README.md b/roles/check_healtz/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/check_healtz/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/check_healtz/defaults/main.yml b/roles/check_healtz/defaults/main.yml new file mode 100644 index 0000000..520e0ce --- /dev/null +++ b/roles/check_healtz/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for roles/check_healtz diff --git a/roles/check_healtz/handlers/main.yml b/roles/check_healtz/handlers/main.yml new file mode 100644 index 0000000..0b285c7 --- /dev/null +++ b/roles/check_healtz/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for roles/check_healtz diff --git a/roles/check_healtz/meta/_main.yml b/roles/check_healtz/meta/_main.yml new file mode 100644 index 0000000..6f91fd3 --- /dev/null +++ b/roles/check_healtz/meta/_main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/check_healtz/meta/main.yml b/roles/check_healtz/meta/main.yml new file mode 100644 index 0000000..3a3ed7c --- /dev/null +++ b/roles/check_healtz/meta/main.yml @@ -0,0 +1,37 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + +allow_duplicates: true diff --git a/roles/check_healtz/tasks/main.yml b/roles/check_healtz/tasks/main.yml new file mode 100644 index 0000000..ff0490a --- /dev/null +++ b/roles/check_healtz/tasks/main.yml @@ -0,0 +1,17 @@ +#SPDX-License-Identifier: MIT-0 +--- +# tasks file for roles/check_healtz +- name: Vérifier les services web + ansible.builtin.uri: + url: "{{ item }}" + method: GET + status_code: 200 + validate_certs: true + register: health_check + retries: 12 + delay: 10 + until: health_check.status == 200 + loop: "{{ health_urls | default([]) }}" + loop_control: + label: "{{ item }}" + delegate_to: localhost diff --git a/roles/check_healtz/tests/inventory b/roles/check_healtz/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/roles/check_healtz/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/roles/check_healtz/tests/test.yml b/roles/check_healtz/tests/test.yml new file mode 100644 index 0000000..d200b24 --- /dev/null +++ b/roles/check_healtz/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - roles/check_healtz diff --git a/roles/check_healtz/vars/main.yml b/roles/check_healtz/vars/main.yml new file mode 100644 index 0000000..b257573 --- /dev/null +++ b/roles/check_healtz/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for roles/check_healtz diff --git a/roles/proxmox_snapshot/README.md b/roles/proxmox_snapshot/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/proxmox_snapshot/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/proxmox_snapshot/defaults/main.yml b/roles/proxmox_snapshot/defaults/main.yml new file mode 100644 index 0000000..9e9a4b6 --- /dev/null +++ b/roles/proxmox_snapshot/defaults/main.yml @@ -0,0 +1,4 @@ +proxmox_snapshot_api_host: "" +proxmox_snapshot_api_user: "" +proxmox_snapshot_api_token_id: "" +proxmox_snapshot_api_token_secret: "" #Vault diff --git a/roles/proxmox_snapshot/handlers/main.yml b/roles/proxmox_snapshot/handlers/main.yml new file mode 100644 index 0000000..5eb9d5a --- /dev/null +++ b/roles/proxmox_snapshot/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for roles/proxmox_snapshot diff --git a/roles/proxmox_snapshot/meta/main.yml b/roles/proxmox_snapshot/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/proxmox_snapshot/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/proxmox_snapshot/tasks/main.yml b/roles/proxmox_snapshot/tasks/main.yml new file mode 100644 index 0000000..948e078 --- /dev/null +++ b/roles/proxmox_snapshot/tasks/main.yml @@ -0,0 +1,11 @@ +- name: Création d'un snapshot + community.proxmox.proxmox_snap: + api_host: "{{ proxmox_snapshot_api_host }}" + api_user: "{{ proxmox_snapshot_api_user }}" + api_token_id: "{{ proxmox_snapshot_api_token_id }}" + api_token_secret: "{{ proxmox_snapshot_api_token_secret }}" + vmid: "{{ proxmox_snapshot_vmid }}" + state: present + snapname: "ansible_sandbox_snapshot_update_os" + validate_certs: "{{ proxmox_snapshot_validate_certs }}" + delegate_to: localhost diff --git a/roles/proxmox_snapshot/tests/inventory b/roles/proxmox_snapshot/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/proxmox_snapshot/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/proxmox_snapshot/tests/test.yml b/roles/proxmox_snapshot/tests/test.yml new file mode 100644 index 0000000..99c5d1a --- /dev/null +++ b/roles/proxmox_snapshot/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - roles/proxmox_snapshot diff --git a/roles/proxmox_snapshot/vars/main.yml b/roles/proxmox_snapshot/vars/main.yml new file mode 100644 index 0000000..cfa5fce --- /dev/null +++ b/roles/proxmox_snapshot/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for roles/proxmox_snapshot diff --git a/roles/proxmox_snapshot_remove/README.md b/roles/proxmox_snapshot_remove/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/proxmox_snapshot_remove/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/proxmox_snapshot_remove/defaults/main.yml b/roles/proxmox_snapshot_remove/defaults/main.yml new file mode 100644 index 0000000..219fa07 --- /dev/null +++ b/roles/proxmox_snapshot_remove/defaults/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# defaults file for roles/proxmox_snapshot_remove diff --git a/roles/proxmox_snapshot_remove/handlers/main.yml b/roles/proxmox_snapshot_remove/handlers/main.yml new file mode 100644 index 0000000..598b352 --- /dev/null +++ b/roles/proxmox_snapshot_remove/handlers/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# handlers file for roles/proxmox_snapshot_remove diff --git a/roles/proxmox_snapshot_remove/meta/main.yml b/roles/proxmox_snapshot_remove/meta/main.yml new file mode 100644 index 0000000..6f91fd3 --- /dev/null +++ b/roles/proxmox_snapshot_remove/meta/main.yml @@ -0,0 +1,35 @@ +#SPDX-License-Identifier: MIT-0 +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.2 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/proxmox_snapshot_remove/tasks/main.yml b/roles/proxmox_snapshot_remove/tasks/main.yml new file mode 100644 index 0000000..c633a3f --- /dev/null +++ b/roles/proxmox_snapshot_remove/tasks/main.yml @@ -0,0 +1,12 @@ +- name: Suppresion du snapshot + community.proxmox.proxmox_snap: + api_host: "{{ proxmox_snapshot_api_host }}" + api_user: "{{ proxmox_snapshot_api_user }}" + api_token_id: "{{ proxmox_snapshot_api_token_id }}" + api_token_secret: "{{ proxmox_snapshot_api_token_secret }}" + vmid: "{{ proxmox_snapshot_vmid }}" + state: absent + snapname: "ansible_sandbox_snapshot_update_os" + timeout: 300 + validate_certs: "{{ proxmox_snapshot_validate_certs }}" + delegate_to: localhost diff --git a/roles/proxmox_snapshot_remove/tests/inventory b/roles/proxmox_snapshot_remove/tests/inventory new file mode 100644 index 0000000..03ca42f --- /dev/null +++ b/roles/proxmox_snapshot_remove/tests/inventory @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +localhost + diff --git a/roles/proxmox_snapshot_remove/tests/test.yml b/roles/proxmox_snapshot_remove/tests/test.yml new file mode 100644 index 0000000..a77f97f --- /dev/null +++ b/roles/proxmox_snapshot_remove/tests/test.yml @@ -0,0 +1,6 @@ +#SPDX-License-Identifier: MIT-0 +--- +- hosts: localhost + remote_user: root + roles: + - roles/proxmox_snapshot_remove diff --git a/roles/proxmox_snapshot_remove/vars/main.yml b/roles/proxmox_snapshot_remove/vars/main.yml new file mode 100644 index 0000000..7d3a6ae --- /dev/null +++ b/roles/proxmox_snapshot_remove/vars/main.yml @@ -0,0 +1,3 @@ +#SPDX-License-Identifier: MIT-0 +--- +# vars file for roles/proxmox_snapshot_remove diff --git a/roles/update_os/README.md b/roles/update_os/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/update_os/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/update_os/defaults/main.yml b/roles/update_os/defaults/main.yml new file mode 100644 index 0000000..9c75a12 --- /dev/null +++ b/roles/update_os/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for roles/update_os diff --git a/roles/update_os/handlers/main.yml b/roles/update_os/handlers/main.yml new file mode 100644 index 0000000..a1a56e3 --- /dev/null +++ b/roles/update_os/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for roles/update_os diff --git a/roles/update_os/meta/main.yml b/roles/update_os/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/roles/update_os/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/roles/update_os/tasks/main.yml b/roles/update_os/tasks/main.yml new file mode 100644 index 0000000..21822e3 --- /dev/null +++ b/roles/update_os/tasks/main.yml @@ -0,0 +1,25 @@ +- name: Mise à jour du cache APT + ansible.builtin.apt: + update_cache: true + cache_valid_time: 3600 + +- name: Mise à jour complète + ansible.builtin.apt: + upgrade: dist + autoremove: true + autoclean: true + +- name: Vérifier si un reboot est nécessaire + ansible.builtin.stat: + path: /var/run/reboot-required + register: reboot_required + +- name: Redémarrer la machine + ansible.builtin.reboot: + reboot_timeout: 900 + post_reboot_delay: 20 + when: reboot_required.stat.exists + +- name: Attendre SSH + ansible.builtin.wait_for_connection: + timeout: 300 diff --git a/roles/update_os/tests/inventory b/roles/update_os/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/update_os/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/update_os/tests/test.yml b/roles/update_os/tests/test.yml new file mode 100644 index 0000000..95c47ce --- /dev/null +++ b/roles/update_os/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - roles/update_os diff --git a/roles/update_os/vars/main.yml b/roles/update_os/vars/main.yml new file mode 100644 index 0000000..8867995 --- /dev/null +++ b/roles/update_os/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for roles/update_os