Guest User

Untitled

a guest
Jan 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. ---
  2. - name: Create dynamic inventory for ssh connection by password
  3. hosts: localhost
  4. connection: local
  5. gather_facts: no
  6. vars:
  7. server_list:
  8. - {hostname: 'machine1', adresse_ip: '10.123.123.123', osadmin_password: 'azerty', root_password: 'ytreza'}
  9. - {hostname: 'machine2', adresse_ip: '10.123.123.124', osadmin_password: 'azerty', root_password: 'ytreza'}
  10.  
  11. tasks:
  12. - name: Create inventory
  13. add_host:
  14. group: 'RHEL73_openssh'
  15. name: '{{ item.hostname }}'
  16. ansible_host: '{{ item.adresse_ip }}'
  17. ansible_user: 'osadmin'
  18. ansible_ssh_pass: '{{ item.osadmin_password }}'
  19. ansible_become: true
  20. ansible_become_method: 'su'
  21. ansible_become_user: 'root'
  22. ansible_become_pass: '{{ item.root_password }}'
  23. with_items: '{{ server_list }}'
  24.  
  25. - name: Update openssh server and
  26. hosts: 'RHEL73_openssh'
  27. become: true
  28.  
  29. tasks:
  30. - name: Update openssh
  31. yum:
  32. name: 'openssh'
  33. state: 'latest'
  34. enablerepo: 'standard'
  35. when: ansible_os_family == "RedHat" and ansible_distribution_version == "7.3"
  36. register: updateOpenssh
  37.  
  38. - name: restart sshd
  39. systemd:
  40. name: sshd.service
  41. state: 'restarted'
  42. daemon_reload: yes
  43. when: ansible_os_family == "RedHat" and ansible_distribution_version == "7.3" and updateOpenssh|changed
  44. ignore_errors: true
  45. register: sshdReloadError
  46.  
  47. - name: force sshd restart when bug
  48. shell: "(sleep 3;killall sshd; service sshd start)&"
  49. async: 1
  50. poll: 0
  51. ignore_errors: true
  52. when: sshdReloadError|failed
Add Comment
Please, Sign In to add comment