1.6 KiB
Atelier d'introduction
ansible cibles -u formation -k -m command -a uptime -o
ansible cibles -u formation -k -m copy -a "src=/etc/profile.d/z_my_profile.sh dest=/etc/profile.d mode=0644 owner=root group=root"
ansible cibles -u formation -k -m yum -a "name=vim-enhanced state=present"
ansible cibles -u formation -k -m yum -a "name=nano state=absent"
ansible cibles -u formation -k -m file -a "path=/srv/sib owner=formation state=directory"
ansible cibles -u formation -k -m lineinfile -a "path=/etc/profile.d/editor.sh create=true line='export EDITOR=vim'"
ansible cibles -u formation -k -m get_url -a "url=https://cours.opendoor.fr/Fichiers/vimrc dest=/etc/vimrc mode=0644"
ansible cibles -u formation -k -m service -a "name=crond state=restarted"
Setup
ansible localhost -m openssh_keypair -a "path=/home/formation/.ssh/id_rsa owner=formation group=formation" -u formation
#l'inversion des quotes permet l'utilisation du ! dans le mot de passe ansible cibles -u formation -k -m user -a 'user=ansible password={{ "123Soleil!"| password_hash( "sha512", 65534 | random( seed=inventory_hostname ) | string ) }} create_home=yes home=/home/ansible'
ansible cibles -u formation -k -m lineinfile -a "path=/etc/sudoers.d/ansible state=present create=yes line='ansible ALL=(ALL) NOPASSWD: ALL' validate='/usr/sbin/visudo -cf %s'"
ansible cibles -u formation -k -m copy -a "dest=/etc/sudoers.d/ansible content='ansible ALL=(ALL) NOPASSWD: ALL' validate='/usr/sbin/visudo -cf %s'"
ansible cibles -u formation -k -m authorized_key -a "key={{ lookup( 'file', '~/.ssh/id_rsa.pub') }} user=ansible"