This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docpublic:systemes:ansible_init [2022/08/20 08:52] adminjp [ansible boucle] |
docpublic:systemes:ansible_init [2022/08/21 08:49] (current) adminjp [ansible module ssh] |
||
---|---|---|---|
Line 1477: | Line 1477: | ||
PLAY RECAP ****************************************************************************************************** | PLAY RECAP ****************************************************************************************************** | ||
node3 : ok=2 changed=1 | node3 : ok=2 changed=1 | ||
+ | </ | ||
+ | |||
+ | ==== dictionnaire dans group_vars ==== | ||
+ | |||
+ | d'un point de vue organisation, | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | mydict: | ||
+ | - { dir: ansdirA, fichier: " | ||
+ | - { dir: ansdirB, fichier: " | ||
+ | - { dir: ansdirC, fichier: " | ||
+ | </ | ||
+ | |||
+ | avec dans le playbook un appel a ce dictionnaire | ||
+ | |||
+ | < | ||
+ | with_items: | ||
+ | {{ mydict }} | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== ansible module apt ==== | ||
+ | |||
+ | * https:// | ||
+ | |||
+ | installer un paquet , plein d' | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | --- | ||
+ | - name: J_Playbook_Apt | ||
+ | hosts: node3 | ||
+ | become: yes | ||
+ | tasks: | ||
+ | - name: gestion_apt | ||
+ | apt: | ||
+ | name: tree | ||
+ | state: latest | ||
+ | update_cache: | ||
+ | cache_valid_time: | ||
+ | </ | ||
+ | |||
+ | le //state: present// est moins risqué en terme d' | ||
+ | |||
+ | === execution === | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | ... | ||
+ | TASK [gestion_apt] ********************************************************************************************** | ||
+ | Saturday 20 August 2022 11:29:43 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | PLAY RECAP ****************************************************************************************************** | ||
+ | node3 : ok=2 changed=1 | ||
+ | |||
+ | Saturday 20 August 2022 11:29:58 +0200 (0: | ||
+ | =============================================================================== | ||
+ | gestion_apt --------------------------------------------------------------------------------------------- 15.74s | ||
+ | Gathering Facts ------------------------------------------------------------------------------------------ 1.39s | ||
+ | </ | ||
+ | |||
+ | |||
+ | === supression === | ||
+ | |||
+ | supression totale | ||
+ | |||
+ | < | ||
+ | - name: gestion_apt | ||
+ | apt: | ||
+ | name: tree | ||
+ | state: absent | ||
+ | purge: yes | ||
+ | autoremove: yes | ||
+ | </ | ||
+ | |||
+ | ==== ansible module reboot ==== | ||
+ | |||
+ | * https:// | ||
+ | |||
+ | on demande un reboot sur la base de la presence d'un fichier | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | --- | ||
+ | - name: J_Playbook_File_Reboot | ||
+ | hosts: node3 | ||
+ | become: yes | ||
+ | tasks: | ||
+ | - name: create_fileR | ||
+ | file: | ||
+ | path: "/ | ||
+ | state: touch | ||
+ | - name: stat_fileR | ||
+ | stat: | ||
+ | path: "/ | ||
+ | register: __stat_fileR | ||
+ | |||
+ | - name: reboot_node | ||
+ | reboot: | ||
+ | msg: " | ||
+ | connect_timeout: | ||
+ | reboot_timeout: | ||
+ | pre_reboot_delay: | ||
+ | post_reboot_delay: | ||
+ | test_command: | ||
+ | when: __stat_fileR.stat.exists | ||
+ | |||
+ | - name: reboot_ok | ||
+ | file: | ||
+ | path: "/ | ||
+ | state: touch | ||
+ | </ | ||
+ | |||
+ | === execution === | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | BECOME password: | ||
+ | |||
+ | PLAY [J_Playbook_File_Reboot] *********************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ****************************************************************************** | ||
+ | Saturday 20 August 2022 11:54:11 +0200 (0: | ||
+ | ok: [node3] | ||
+ | |||
+ | TASK [create_fileR] ********************************************************************************* | ||
+ | Saturday 20 August 2022 11:54:12 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | TASK [stat_fileR] *********************************************************************************** | ||
+ | Saturday 20 August 2022 11:54:12 +0200 (0: | ||
+ | ok: [node3] | ||
+ | |||
+ | TASK [reboot_node] ********************************************************************************** | ||
+ | Saturday 20 August 2022 11:54:12 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | TASK [reboot_ok] ************************************************************************************ | ||
+ | Saturday 20 August 2022 11:55:25 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | PLAY RECAP ****************************************************************************************** | ||
+ | node3 : ok=5 changed=3 | ||
+ | |||
+ | Saturday 20 August 2022 11:55:26 +0200 (0: | ||
+ | =============================================================================== | ||
+ | reboot_node --------------------------------------------------------------------------------- 73.09s | ||
+ | reboot_ok ------------------------------------------------------------------------------------ 0.86s | ||
+ | Gathering Facts ------------------------------------------------------------------------------ 0.86s | ||
+ | stat_fileR ----------------------------------------------------------------------------------- 0.30s | ||
+ | create_fileR --------------------------------------------------------------------------------- 0.29s | ||
+ | </ | ||
+ | |||
+ | ==== ansible module ssh ==== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | genérer une clée ssh et la deployer | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | --- | ||
+ | - name: J_Playbook_sshKey | ||
+ | hosts: node3 | ||
+ | become: yes | ||
+ | tasks: | ||
+ | - name: create_sshKey | ||
+ | openssh_keypair: | ||
+ | path: "/ | ||
+ | type: rsa | ||
+ | size: 2048 | ||
+ | state: present | ||
+ | force: no | ||
+ | #delegate a localhost pour jouer ça sur notre server-node | ||
+ | delegate_to: | ||
+ | #le faire tourner une seule fois , meme si +sieurs hosts | ||
+ | run_once: yes | ||
+ | </ | ||
+ | |||
+ | === execution === | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | BECOME password: | ||
+ | |||
+ | PLAY [J_Playbook_sshKey] **************************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ****************************************************************************** | ||
+ | Saturday 20 August 2022 20:45:52 +0200 (0: | ||
+ | ok: [node3] | ||
+ | |||
+ | TASK [create_sshKey] ******************************************************************************** | ||
+ | Saturday 20 August 2022 20:45:53 +0200 (0: | ||
+ | changed: [node3 -> localhost] | ||
+ | |||
+ | PLAY RECAP ****************************************************************************************** | ||
+ | node3 : ok=2 changed=1 | ||
+ | |||
+ | Saturday 20 August 2022 20:45:53 +0200 (0: | ||
+ | =============================================================================== | ||
+ | Gathering Facts ------------------------------------------------------------------------------ 0.86s | ||
+ | create_sshKey -------------------------------------------------------------------------------- 0.21s | ||
+ | |||
+ | ans@disi-dellat: | ||
+ | -rw-r--r-- 1 root root 382 août 20 20:45 / | ||
+ | -rw------- 1 root root 1799 août 20 20:45 / | ||
+ | </ | ||
+ | |||
+ | ==== deploy ssh-key ==== | ||
+ | |||
+ | apres generation locale de la clé (pas besoin d' | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | --- | ||
+ | - name: J_Playbook_sshKey | ||
+ | hosts: node3 | ||
+ | become: yes | ||
+ | tasks: | ||
+ | - name: create_sshKey | ||
+ | openssh_keypair: | ||
+ | path: "/ | ||
+ | type: rsa | ||
+ | size: 2048 | ||
+ | state: present | ||
+ | force: no | ||
+ | #delegate a localhost pour jouer ça sur notre server-node | ||
+ | delegate_to: | ||
+ | #le faire tourner une seule fois , meme si +sieurs hosts | ||
+ | run_once: yes | ||
+ | |||
+ | - name: create_user_adma | ||
+ | user: | ||
+ | name: adma | ||
+ | shell: /bin/bash | ||
+ | groups: sudo | ||
+ | append: yes | ||
+ | password: "{{ ' | ||
+ | become: yes | ||
+ | |||
+ | - name: add_adma_sudoers | ||
+ | copy: | ||
+ | dest: "/ | ||
+ | content: "adma ALL=(ALL) NOPASSWD: ALL" | ||
+ | become: yes | ||
+ | |||
+ | - name: deploy_sshKey | ||
+ | authorized_key: | ||
+ | user: adma | ||
+ | key: "{{ lookup(' | ||
+ | state: present | ||
+ | become: yes | ||
+ | </ | ||
+ | |||
+ | === execution === | ||
+ | |||
+ | < | ||
+ | ans@disi-dellat: | ||
+ | BECOME password: | ||
+ | |||
+ | PLAY [J_Playbook_sshKey] **************************************************************************** | ||
+ | |||
+ | TASK [Gathering Facts] ****************************************************************************** | ||
+ | Sunday 21 August 2022 10:47:05 +0200 (0: | ||
+ | ok: [node3] | ||
+ | |||
+ | TASK [create_sshKey] ******************************************************************************** | ||
+ | Sunday 21 August 2022 10:47:06 +0200 (0: | ||
+ | ok: [node3 -> localhost] | ||
+ | |||
+ | TASK [create_user_adma] ***************************************************************************** | ||
+ | Sunday 21 August 2022 10:47:06 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | TASK [add_adma_sudoers] ***************************************************************************** | ||
+ | Sunday 21 August 2022 10:47:07 +0200 (0: | ||
+ | ok: [node3] | ||
+ | |||
+ | TASK [deploy_sshKey] ******************************************************************************** | ||
+ | Sunday 21 August 2022 10:47:07 +0200 (0: | ||
+ | changed: [node3] | ||
+ | |||
+ | PLAY RECAP ****************************************************************************************** | ||
+ | node3 : ok=5 changed=2 | ||
+ | |||
+ | Sunday 21 August 2022 10:47:08 +0200 (0: | ||
+ | =============================================================================== | ||
+ | Gathering Facts ------------------------------------------------------------------------------ 1.25s | ||
+ | deploy_sshKey -------------------------------------------------------------------------------- 0.66s | ||
+ | add_adma_sudoers ----------------------------------------------------------------------------- 0.62s | ||
+ | create_user_adma ----------------------------------------------------------------------------- 0.50s | ||
+ | create_sshKey -------------------------------------------------------------------------------- 0.19s | ||
</ | </ |