<commit_before># Upgrades the hidden secondary in a mongo cluster if one exists
#
# This is useful for using the hidden secondary to sniff out any problems with
# your point upgrade before you upgrade your primary/secondary servers using the
# mongo_rolling_upgrade.yml play
#
# This play expects to have access to a config file where MONGO_RS_CONFIG, as described
# in the mongo_3_0 role, is defined, as well as MONGO_ADMIN_USER and MONGO_ADMIN_PASSWORD.
#
# ansible-playbook -i 127.0.0.1, mongo_upgrade_hidden_secondaries.yml -e@/path/to/config-file.yml
#
# This play uses MONGO_RS_CONFIG to find a host to connect to and fetch replset config and build an
# inventory, so you can just target localhost.
#
# If there are no hidden secondaries, the 'Upgrade hidden members' task will just skip.

- name: Find hidden secondaries
  hosts: 127.0.0.1
  connection: local
  gather_facts: False
  tasks:
    - name: Get configuration of mongo cluster
      mongodb_rs_config:
        host: "{{ (MONGO_RS_CONFIG.members|map(attribute='host')|list)[0] }}"
        username: "{{ MONGO_ADMIN_USER }}"
        password: "{{ <PASSWORD> }}"
      register: rs_config
    - name: Build inventory of hidden members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: hidden_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.hidden }}"
    - name: Build inventory of secondary members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: secondary_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.secondary }}"
    - name: Build inventory of primary members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: primary_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.primary }}"

- name: Upgrade hidden members
  hosts: hidden_hosts
  gather_facts: True
  become: True
  vars_files:
    - ../roles/mongo_3_0/defaults/main.yml
  tasks:
    - name: install mongo server and recommends
      apt:
        pkg: "{{ item }}"
        state: present
        install_recommends: yes
        force: yes
        update_cache: yes
      with_items: mongodb_debian_pkgs
    - name: wait for mongo server to start
      wait_for:
        port: 27017
        delay: 2
    - name: Wait for the replica set to update and (if needed) elect a primary
      mongodb_rs_status:
          host: "{{ ansible_default_ipv4['address'] }}"
          username: "{{ MONGO_ADMIN_USER }}"
          password: "{{ <PASSWORD> }}"
      register: status
      # This ensures that no servers are in a state other than PRIMARY or SECONDARY.  https://docs.mongodb.com/manual/reference/replica-states/
      until: status.status is defined and not (['PRIMARY','SECONDARY'] | symmetric_difference(status.status.members|map(attribute='stateStr')|list|unique))
      retries: 5
      delay: 2<commit_msg>Add SKIP_PRIMARY to allow partial cluster upgrades<commit_after># Upgrades a full mongo cluster, starting with the hidden members, then the
# secondary, and finally steps down the primary and upgrades it.  It checks along
# the way for a healthy cluster, failing if that is not true.
#
# This play expects to have access to a config file where MONGO_RS_CONFIG, as described
# in the mongo_3_0 role, is defined, as well as MONGO_ADMIN_USER and MONGO_ADMIN_PASSWORD.
#
# ansible-playbook -i 127.0.0.1, mongo_rolling_upgrade.yml -e@/path/to/config-file.yml
#
# This play uses MONGO_RS_CONFIG to find a host to connect to and fetch replset config and build an
# inventory, so you can just target localhost.
#
# If there are no hidden secondaries, the 'Upgrade hidden members' task block will just skip.
#
# This will process a hidden secondary twice - first as a 'hidden' server, then as a 'secondary' but
# this is effectively a no-op except for apt checking the versions and then checking that mongo is running.
# It is valid to have other types of hidden machines, so this seemed better than skipping.
#
# If you wish to avoid updating the primary, you can add -e 'SKIP_PRIMARY=true' to your ansible
# invocation.

- name: Find hidden secondaries
  hosts: 127.0.0.1
  connection: local
  gather_facts: False
  vars:
    - SKIP_PRIMARY: False
  tasks:
    - name: Get configuration of mongo cluster
      mongodb_rs_config:
        host: "{{ (MONGO_RS_CONFIG.members|map(attribute='host')|list)[0] }}"
        username: "{{ MONGO_ADMIN_USER }}"
        password: "{{ <PASSWORD> }}"
      register: rs_config
    - name: Build inventory of hidden members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: hidden_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.hidden }}"
    - name: Build inventory of secondary members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: secondary_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.secondary }}"
    - name: Build inventory of primary members
      add_host:
        hostname: "{{ (item.host.split(':'))[0] }}"
        instance_id: "{{ item._id }}"
        groups: primary_hosts
        ansible_ssh_user: ubuntu
      with_items:
        - "{{ rs_config.primary }}"
      when: not SKIP_PRIMARY

- name: Upgrade hidden members
  hosts: hidden_hosts
  gather_facts: True
  become: True
  vars_files:
    - ../roles/mongo_3_0/defaults/main.yml
  tasks:
    - name: install mongo server and recommends
      apt:
        pkg: "{{ item }}"
        state: present
        install_recommends: yes
        force: yes
        update_cache: yes
      with_items: mongodb_debian_pkgs
    - name: wait for mongo server to start
      wait_for:
        port: 27017
        delay: 2
    - name: Wait for the replica set to update and (if needed) elect a primary
      mongodb_rs_status:
          host: "{{ ansible_default_ipv4['address'] }}"
          username: "{{ MONGO_ADMIN_USER }}"
          password: "{{ <PASSWORD> }}"
      register: status
      # This ensures that no servers are in a state other than PRIMARY or SECONDARY.  https://docs.mongodb.com/manual/reference/replica-states/
      until: status.status is defined and not (['PRIMARY','SECONDARY'] | symmetric_difference(status.status.members|map(attribute='stateStr')|list|unique))
      retries: 5
      delay: 2
{'fraction_non_alphanumeric': 0.10117145899893504, 'fraction_numerical': 0.008823976875095086, 'mean_word_length': 2.889940828402367, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '5315529', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1997, 'n_words': 639}