## Atelier d'introduction ansible cibles -m command -a uptime -o ansible cibles -m copy -a 'src=/etc/profile.d/z_my_profile.sh dest=/etc/profile.d mode=0644 owner=root group=root' ansible centos -m yum -a 'name=vim-enhanced state=present' ansible centos -m yum -a 'name=nano state=absent' ansible cibles -m file -a 'path=/srv/sib owner=formation state=directory' ansible cibles -m lineinfile -a 'path=/etc/profile.d/editor.sh create=true line="export EDITOR=vim" state=present' ansible cibles -m get_url -a 'url=https://cours.opendoor.fr/Fichiers/vimrc dest=/etc/vimrc mode=0644' ansible centos -m service -a 'name=crond state=restarted' ## Setup ```bash ansible localhost -m community.crypto.openssh_keypair -a 'path=/home/formation/.ssh/id_rsa owner=formation group=formation' -u formation ``` ⚠️ si vous générez une clé dans un répertoire non standard, pensez à utiliser l'option -i lors des prochaines commandes ssh, et le paramètre de configuration "private_key_file" pour indiquer à ansible la clé qu'il doit utiliser pour les connexions #l'inversion des quotes permet l'utilisation du ! dans le mot de passe ```bash ansible cibles -m ansible.builtin.user -a 'user=ansible password={{ "123Soleil!"| password_hash( "sha512", 65534 | random(seed=inventory_hostname) | string) }} create_home=yes home=/home/ansible' ``` ```bash ansible cibles -m ansible.builtin.lineinfile -a 'path=/etc/sudoers.d/ansible state=present create=yes line="ansible ALL=(ALL) NOPASSWD: ALL" validate="/usr/sbin/visudo -cf %s"' ``` ```bash ansible cibles -m ansible.builtin.copy -a 'dest=/etc/sudoers.d/ansible content="ansible ALL=(ALL) NOPASSWD: ALL" validate="/usr/sbin/visudo -cf %s"' ``` ```bash ansible cibles -o -m community.general.sudoers -a 'name="ansible" user=ansible commands=ALL nopassword=true' ``` ```bash ansible cibles -u formation -k -m ansible.posix.authorized_key -a 'key={{ lookup( "file", "~/.ssh/id_rsa.pub") }} user=ansible' ``` ```bash ansible localhost -m community.general.ini_file -a 'option=remote_user value=ansible section=defaults path=/etc/ansible/ansible.cfg' ansible localhost -m community.general.ini_file -a 'option=ask_pass value=False section=defaults path=/etc/ansible/ansible.cfg' ansible localhost -m community.general.ini_file -a 'option=become_ask_pass value=False section=privilege_escalation path=/etc/ansible/ansible.cfg' ```