---
- name: Set session timeout
  hosts: all
  tasks:
  - lineinfile:
      dest: /etc/profile
      regexp: '^TMOUT=.*'
      insertbefore: '^readonly TMOUT'
      line: 'TMOUT={{shell_timeout}}'
      state: "{{ 'absent' if (shell_timeout == 0) else 'present' }}"

- name: Set TMOUT readonly
  hosts: all
  tasks:
  - lineinfile:
      dest: /etc/profile
      regexp: '^readonly TMOUT'
      insertafter: 'TMOUT={{shell_timeout}}'
      line: 'readonly TMOUT'
      state: "{{ 'absent' if (shell_timeout == 0) else 'present' }}"

- name: Set export TMOUT
  hosts: all
  tasks:
  - lineinfile:
      dest: /etc/profile
      regexp: '^export TMOUT.*'
      insertafter: 'readonly TMOUT'
      line: 'export TMOUT'
      state: "{{ 'absent' if (shell_timeout == 0) else 'present' }}"
