tech:ansible_sudo_su_become_method
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:ansible_sudo_su_become_method [2025/11/11 19:42] – Jean-Baptiste | tech:ansible_sudo_su_become_method [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Ansible sudo su become method | ||
| + | |||
| + | N'est pas autorisé | ||
| + | ~~~bash | ||
| + | sudo -u testplop ls | ||
| + | ~~~ | ||
| + | |||
| + | Mais est autorisé : | ||
| + | ~~~bash | ||
| + | sudo su - testplop | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | User_Alias | ||
| + | |||
| + | Cmnd_Alias | ||
| + | /bin/su - testplop | ||
| + | |||
| + | Defaults: | ||
| + | |||
| + | USER_T_USERC1 | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Alors que ça serait tellement plus propre de faire : | ||
| + | ~~~bash | ||
| + | Runas_Alias RUNAS_DBA_ALL = oracle, testplop | ||
| + | # | ||
| + | USER_T_USERC1 ALL= (RUNAS_DBA_ALL) EXEC: NOPASSWD: ALL | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Solution 1 | ||
| + | |||
| + | Utiliser le become plugin **community.general.sudosu** | ||
| + | |||
| + | |||
| + | Pas applicable dans notre cas, et nous avons l' | ||
| + | ~~~ | ||
| + | fatal: [test-ansible]: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Car si il est possible de faire : | ||
| + | ~~~bash | ||
| + | sudo su - testplop | ||
| + | ~~~ | ||
| + | |||
| + | Il n'est pas possible de faire : | ||
| + | ~~~bash | ||
| + | sudo su -l testplop -c ' | ||
| + | ~~~ | ||
| + | |||
| + | Il faudrait la conf sudoers suivantes : | ||
| + | |||
| + | ~~~bash | ||
| + | Cmnd_Alias | ||
| + | /bin/su -l testplop * | ||
| + | ~~~ | ||
| + | |||
| + | Cela n'est pas sans poser des problèmes de sécurité. | ||
| + | |||
| + | Voici la conf | ||
| + | |||
| + | ~~~bash | ||
| + | ansible-galaxy collection install community.general | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | `play.yml` | ||
| + | ~~~yaml | ||
| + | |||
| + | # | ||
| + | --- | ||
| + | |||
| + | - name: test sudosu | ||
| + | hosts: srvtest | ||
| + | gather_facts: | ||
| + | become_method: | ||
| + | become_user: | ||
| + | become: true | ||
| + | |||
| + | tasks: | ||
| + | |||
| + | - name: test | ||
| + | command: id | ||
| + | register: cmd_ls | ||
| + | |||
| + | - name: test | ||
| + | debug: | ||
| + | var: cmd_ls.stdout_lines | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Solution 2 | ||
| + | |||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | #!/bin/bash | ||
| + | # | ||
| + | #sudosu.sh " | ||
| + | |||
| + | if [ $# -lt 3 ]; then | ||
| + | echo 'Not enough arguments: sudosu.sh " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | if [ x" | ||
| + | echo 'Wrong 2nd arg: sudosu.sh " | ||
| + | exit 1 | ||
| + | fi | ||
| + | |||
| + | printf ' | ||
| + | ~~~ | ||
| + | |||
| + | `play.yml` | ||
| + | ~~~yaml | ||
| + | # | ||
| + | --- | ||
| + | |||
| + | - name: test | ||
| + | hosts: test-ansible | ||
| + | gather_facts: | ||
| + | become_method: | ||
| + | # become_flags: | ||
| + | # become_flags: | ||
| + | become_exe: / | ||
| + | become_user: | ||
| + | become: true | ||
| + | |||
| + | tasks: | ||
| + | |||
| + | - name: test | ||
| + | command: id | ||
| + | register: cmd_ls | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autres | ||
| + | |||
| + | ~~~bash | ||
| + | ansible-doc -t become -l | ||
| + | ~~~ | ||
| + | |||
