Created
January 11, 2018 17:10
-
-
Save jeanlouisferey/78ea823440f27b936a21c46463c1971b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Create dynamic inventory for ssh connection by password | |
hosts: localhost | |
connection: local | |
gather_facts: no | |
vars: | |
server_list: | |
- {hostname: 'machine1', adresse_ip: '10.123.123.123', osadmin_password: 'azerty', root_password: 'ytreza'} | |
- {hostname: 'machine2', adresse_ip: '10.123.123.124', osadmin_password: 'azerty', root_password: 'ytreza'} | |
tasks: | |
- name: Create inventory | |
add_host: | |
group: 'RHEL73_openssh' | |
name: '{{ item.hostname }}' | |
ansible_host: '{{ item.adresse_ip }}' | |
ansible_user: 'osadmin' | |
ansible_ssh_pass: '{{ item.osadmin_password }}' | |
ansible_become: true | |
ansible_become_method: 'su' | |
ansible_become_user: 'root' | |
ansible_become_pass: '{{ item.root_password }}' | |
with_items: '{{ server_list }}' | |
- name: Update openssh server and | |
hosts: 'RHEL73_openssh' | |
become: true | |
tasks: | |
- name: Update openssh | |
yum: | |
name: 'openssh' | |
state: 'latest' | |
enablerepo: 'standard' | |
when: ansible_os_family == "RedHat" and ansible_distribution_version == "7.3" | |
register: updateOpenssh | |
- name: restart sshd | |
systemd: | |
name: sshd.service | |
state: 'restarted' | |
daemon_reload: yes | |
when: ansible_os_family == "RedHat" and ansible_distribution_version == "7.3" and updateOpenssh|changed | |
ignore_errors: true | |
register: sshdReloadError | |
- name: force sshd restart when bug | |
shell: "(sleep 3;killall sshd; service sshd start)&" | |
async: 1 | |
poll: 0 | |
ignore_errors: true | |
when: sshdReloadError|failed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment