<commit_before>---
#
# edX Configuration
#
# github:     https://github.com/edx/configuration
# wiki:       https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license:    https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role aws
#
# Overview:
#
#
# Dependencies:
#
#
# Example play:
#
#

#
# Start dealing with Jumbo frames issue in mixed MTU deployements in AWS
#
- name: gather ec2 facts for use in other roles
  action: ec2_facts
  tags: 
    - deploy

- shell: >
    /sbin/ifconfig eth0 mtu 1500 up
  when: ansible_distribution in common_debian_variants

- lineinfile: >
    dest=/etc/network/interfaces.d/eth0.cfg
    regexp="^post-up /sbin/ifconfig eth0 mtu 1500"
    line="post-up /sbin/ifconfig eth0 mtu 1500"
    insertafter="^iface"
  when: ansible_distribution in common_debian_variants

#
# End dealing with Jumbo frames issue in mixed MTU deployements in AWS
#

- name: create all service directories
  file: >
    path="{{ item.value.path }}"
    state="directory"
    owner="{{ item.value.owner }}"
    group="{{ item.value.group }}"
    mode="{{ item.value.mode }}"
  with_dict: aws_dirs

- name: install system packages
  apt: >
    pkg={{','.join(aws_debian_pkgs)}}
    state=present
    update_cache=yes

- name: install aws python packages
  pip: >
    name="{{ item }}" state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}"
  with_items: aws_pip_pkgs

- name: get s3cmd
  get_url: >
    url={{ aws_s3cmd_url }}
    dest={{ aws_dirs.data.path }}/

- name: untar s3cmd
  shell: >
    tar xf {{ aws_dirs.data.path }}/{{ aws_s3cmd_version }}.tar.gz
    creates={{ aws_dirs.data.path }}/{{ aws_s3cmd_version }}/s3cmd
    chdir={{ aws_dirs.home.path }}

- name: create symlink for s3cmd
  file: >
    src={{ aws_dirs.home.path }}/{{ aws_s3cmd_version }}/s3cmd
    dest={{ aws_s3cmd }}
    state=link

- name: create s3 log sync script
  template: >
    dest={{ aws_s3_sync_script }}
    src=send-logs-to-s3.j2 mode=0755 owner=root group=root
  when: AWS_S3_LOGS

- name: create symlink for s3 log sync script
  file: >
    state=link
    src={{ aws_s3_sync_script }}
    dest={{ COMMON_BIN_DIR }}/{{ aws_s3_sync_script|basename }}
  when: AWS_S3_LOGS

- name: force logrotate on supervisor stop
  template: >
    src=etc/init/sync-on-stop.conf.j2
    dest=/etc/init/sync-on-stop.conf
    owner=root group=root mode=0644
  when: AWS_S3_LOGS

  # cron job runs the aws s3 sync script
  # this job will log its output to /var/log/aws
- name: cronjob for s3 log sync
  cron:
    name: "cronjob for s3 log sync"
    user: root
    minute: 0
    job: "{{ aws_s3_sync_script }} > /dev/null 2>&1"
    state: absent
  when: AWS_S3_LOGS

 # update the ssh motd on Ubuntu
 # Remove some of the default motd display on ubuntu
 # and add a custom motd.  These do not require an
 # ssh restart
 # Only needed for EC2 instances.
- name: update the ssh motd on Ubuntu
  file: >
    mode=0644
    path={{ item }}
  when: vagrant_home_dir.stat.exists == false
  with_items:
  - "/etc/update-motd.d/10-help-text"
  - "/usr/share/landscape/landscape-sysinfo.wrapper"
  - "/etc/update-motd.d/51-cloudguest"
  - "/etc/update-motd.d/91-release-upgrade"

- name: update /etc/dhcp/dhclient.conf
  template: 
    src: etc/dhcp/dhclient.conf.j2 
    dest: /etc/dhcp/dhclient.conf
  when: COMMON_CUSTOM_DHCLIENT_CONFIG

- name: copy the MOTD template in place
  template:
    dest: "{{ item.dest }}"
    src: "{{ item.src }}"
    owner: root 
    group: root 
    mode: "{{ item.mode | default(644) }}"
  with_items:
    - { src: 'etc/motd.tail.j2', dest: '/etc/motd.tail', mode: '755' }

- name: Copy the sshd_config template in place
  template:
    dest: "{{ item.dest }}"
    src: "{{ item.src }}"
    owner: root 
    group: root 
    mode: "{{ item.mode | default(644) }}"
  register: sshd_config
  with_items:
    - { src: 'etc/ssh/sshd_config.j2', dest: '/etc/ssh/sshd_config' }

- name: restart ssh
  service: name=ssh state=restarted
  sudo: True
  when: sshd_config.changed
<commit_msg>Check for file before altering<commit_after>---
#
# edX Configuration
#
# github:     https://github.com/edx/configuration
# wiki:       https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license:    https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role aws
#
# Overview:
#
#
# Dependencies:
#
#
# Example play:
#
#

#
# Start dealing with Jumbo frames issue in mixed MTU deployements in AWS
#
- name: gather ec2 facts for use in other roles
  action: ec2_facts
  tags: 
    - deploy

- shell: >
    /sbin/ifconfig eth0 mtu 1500 up
  when: ansible_distribution in common_debian_variants

- name: check for eth0.cfg
  stat: path=/etc/network/interfaces.d/eth0.cfg
  register: eth0_cfg
  when: ansible_distribution in common_debian_variants

- lineinfile: >
    dest=/etc/network/interfaces.d/eth0.cfg
    regexp="^post-up /sbin/ifconfig eth0 mtu 1500"
    line="post-up /sbin/ifconfig eth0 mtu 1500"
    insertafter="^iface"
  when: ansible_distribution in common_debian_variants and eth0_cfg.stat.exists

#
# End dealing with Jumbo frames issue in mixed MTU deployements in AWS
#

- name: create all service directories
  file: >
    path="{{ item.value.path }}"
    state="directory"
    owner="{{ item.value.owner }}"
    group="{{ item.value.group }}"
    mode="{{ item.value.mode }}"
  with_dict: aws_dirs

- name: install system packages
  apt: >
    pkg={{','.join(aws_debian_pkgs)}}
    state=present
    update_cache=yes

- name: install aws python packages
  pip: >
    name="{{ item }}" state=present
    extra_args="-i {{ COMMON_PYPI_MIRROR_URL }}"
  with_items: aws_pip_pkgs

- name: get s3cmd
  get_url: >
    url={{ aws_s3cmd_url }}
    dest={{ aws_dirs.data.path }}/

- name: untar s3cmd
  shell: >
    tar xf {{ aws_dirs.data.path }}/{{ aws_s3cmd_version }}.tar.gz
    creates={{ aws_dirs.data.path }}/{{ aws_s3cmd_version }}/s3cmd
    chdir={{ aws_dirs.home.path }}

- name: create symlink for s3cmd
  file: >
    src={{ aws_dirs.home.path }}/{{ aws_s3cmd_version }}/s3cmd
    dest={{ aws_s3cmd }}
    state=link

- name: create s3 log sync script
  template: >
    dest={{ aws_s3_sync_script }}
    src=send-logs-to-s3.j2 mode=0755 owner=root group=root
  when: AWS_S3_LOGS

- name: create symlink for s3 log sync script
  file: >
    state=link
    src={{ aws_s3_sync_script }}
    dest={{ COMMON_BIN_DIR }}/{{ aws_s3_sync_script|basename }}
  when: AWS_S3_LOGS

- name: force logrotate on supervisor stop
  template: >
    src=etc/init/sync-on-stop.conf.j2
    dest=/etc/init/sync-on-stop.conf
    owner=root group=root mode=0644
  when: AWS_S3_LOGS

  # cron job runs the aws s3 sync script
  # this job will log its output to /var/log/aws
- name: cronjob for s3 log sync
  cron:
    name: "cronjob for s3 log sync"
    user: root
    minute: 0
    job: "{{ aws_s3_sync_script }} > /dev/null 2>&1"
    state: absent
  when: AWS_S3_LOGS

 # update the ssh motd on Ubuntu
 # Remove some of the default motd display on ubuntu
 # and add a custom motd.  These do not require an
 # ssh restart
 # Only needed for EC2 instances.
- name: update the ssh motd on Ubuntu
  file: >
    mode=0644
    path={{ item }}
  when: vagrant_home_dir.stat.exists == false
  with_items:
  - "/etc/update-motd.d/10-help-text"
  - "/usr/share/landscape/landscape-sysinfo.wrapper"
  - "/etc/update-motd.d/51-cloudguest"
  - "/etc/update-motd.d/91-release-upgrade"

- name: update /etc/dhcp/dhclient.conf
  template: 
    src: etc/dhcp/dhclient.conf.j2 
    dest: /etc/dhcp/dhclient.conf
  when: COMMON_CUSTOM_DHCLIENT_CONFIG

- name: copy the MOTD template in place
  template:
    dest: "{{ item.dest }}"
    src: "{{ item.src }}"
    owner: root 
    group: root 
    mode: "{{ item.mode | default(644) }}"
  with_items:
    - { src: 'etc/motd.tail.j2', dest: '/etc/motd.tail', mode: '755' }

- name: Copy the sshd_config template in place
  template:
    dest: "{{ item.dest }}"
    src: "{{ item.src }}"
    owner: root 
    group: root 
    mode: "{{ item.mode | default(644) }}"
  register: sshd_config
  with_items:
    - { src: 'etc/ssh/sshd_config.j2', dest: '/etc/ssh/sshd_config' }

- name: restart ssh
  service: name=ssh state=restarted
  sudo: True
  when: sshd_config.changed

{'fraction_non_alphanumeric': 0.13286463298379408, 'fraction_numerical': 0.019065776930409915, 'mean_word_length': 3.128381701918347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3849086', 'n_tokens_mistral': 3247, 'n_tokens_neox': 3142, 'n_words': 754}