#
# playbook to setup and configure test machines. 
# Runs on fedora and rhel/centos
#
#- include: "../include/virt-create.yml myhosts=testbox.scrye.com"

- name: test fedora/epel machines config
  hosts: test
  user: root
  gather_facts: true

  vars_files:
   - /home/kevin/git/scrye-ansible/vars/global.yml
   - /home/kevin/git/scrye-ansible-private/vars.yml

  tasks:

  - name: correct package setup
    yum: state=present name={{ item }}
    with_items:
    - fedora-packager
    - ssmtp
    - zsh
    - fedora-easy-karma
    when: ansible_distribution == "CentOS"

  - name: correct package setup
    dnf: state=present name={{ item }}
    with_items:
    - fedora-packager
    - ssmtp
    - zsh
    - fedora-easy-karma
    - nss_db
    when: ansible_distribution == "Fedora"

  - name: setup sstmp
    copy: src={{ files }}/testmachines/ssmtp.conf dest=/etc/ssmtp/ssmtp.conf owner=root mode=644
    tags:
    - config
    - ssmtp

  - name: make fas dir for fasClient
    file: path=/root/fas state=directory mode=700 owner=root
    tags:
    - config
    - fas_client

  - name: fasClient
    git: repo=git://github.com/fedora-infra/fas.git dest=/root/fas/fas accept_hostkey=true
    tags:
    - config
    - fas_client

  - name: setup fasClient config
    template: src={{ files }}/testmachines/fas.conf.j2 dest=/etc/fas.conf owner=root mode=600
    tags:
    - config
    - fas_client

  - name: setup fasClient Cron job
    copy: src={{ files }}/testmachines/fasClient.cron dest=/etc/cron.daily/fasClient.cron owner=root mode=700
    tags:
    - config
    - fas_client

  - name: run fas_client only if we just installed
    command: /root/fas/fas/client/fasClient -if creates=/var/db/shadow.db
    tags:
    - config
    - fas_client

#
# setup /etc/motd with general info, the hostname, arch, etc. 
#
  - name: setup motd
    template: src={{ files }}/testmachines/motd.j2 dest=/etc/motd owner=root mode=644

  - name: setup sudoers
    copy: src={{ files }}/testmachines/packagers-sudoers dest=/etc/sudoers.d/packagers owner=root mode=600
# Draco is centos5.11, and too old for this
    when: "'{{ansible_fqdn}}' != 'draco.scrye.com'"

  - name: disable ssh agent forwarding
    lineinfile: dest=/etc/ssh/sshd_config regexp="^AllowAgentForwarding " insertafter="^#AllowAgentForwarding " line="AllowAgentForwarding no"
    notify:
    - restart sshd
# Draco is centos5.11, and too old for this
    when: "'{{ansible_fqdn}}' != 'draco.scrye.com'"

  - name: make sure we only have ssmtp
    yum: state=absent name={{ item }}
    with_items:
    - sendmail
    - postfix
    - exim

  roles:

  - dnf-automatic

  handlers:
  - name: restart sshd
    action: service name=sshd state=restarted
