--- # Sets up accounts for DMDirc build agents - hosts: dmdirc-buildagents sudo: yes user: root vars: home_dir: /home/{{ teamcity_user }}/ agent_sh: "{{ home_dir }}/bin/agent.sh" conf: "{{ home_dir }}/conf/buildAgent.properties" pid: "{{ home_dir }}/logs/buildAgent.pid" temp_key: /etc/ansible/data/auto/keys/teamcity-{{ ansible_hostname }} htaccess: /home/dmdirc/www/private/.htaccess header: "# {{ inventory_hostname }}" tasks: - name: create teamcity user user: name={{ teamcity_user }} generate_ssh_key=yes - name: install pre-requisites apt: pkg={{ item }} with_items: - ant - git - unzip - openjdk-7-jdk - nsis - dpkg-dev - cdbs - debhelper - javahelper - mkisofs - alien - fakeroot - name: fetch agent zip sudo_user: "{{ teamcity_user }}" get_url: url=http://teamcity.dmdirc.com/update/buildAgent.zip dest={{ home_dir }} - name: unpack agent zip sudo_user: "{{ teamcity_user }}" command: creates={{ agent_sh }} chdir={{ home_dir }} unzip -o buildAgent.zip - name: make agent.sh executable sudo_user: "{{ teamcity_user }}" file: path={{ agent_sh }} mode=0755 - name: copy default configuration sudo_user: "{{ teamcity_user }}" command: creates={{ conf }} chdir={{ home_dir }}/conf cp buildAgent.dist.properties buildAgent.properties - name: set teamcity server URL sudo_user: "{{ teamcity_user }}" lineinfile: dest={{ conf }} regexp=^serverUrl= line=serverUrl=http://teamcity.dmdirc.com/ - name: set build agent name sudo_user: "{{ teamcity_user }}" lineinfile: dest={{ conf }} regexp=^name= line=name={{ inventory_hostname }} - name: add dmdirc.com to known hosts sudo_user: "{{ teamcity_user }}" lineinfile: dest={{ home_dir }}/.ssh/known_hosts regexp=^dmdirc.com line="dmdirc.com,85.234.138.10 {{ hostvars['renji.org.uk']['ssh_public_key'] }}" - name: retrieve public key sudo_user: "{{ teamcity_user }}" fetch: src={{ home_dir }}/.ssh/id_rsa.pub dest={{ temp_key }} flat=yes - name: add SSH key to dmdirc-artifacts delegate_to: renji.org.uk authorized_key: key="{{ lookup('file', temp_key) }}" user=dmdirc-artifacts - name: add header to private .htaccess file delegate_to: renji.org.uk sudo_user: dmdirc lineinfile: dest={{ htaccess }} line="{{ header }}" insertafter="^# Build agents:" - name: add all IP addresses to .htaccess file delegate_to: renji.org.uk sudo_user: dmdirc lineinfile: dest={{ htaccess }} line="Allow from {{ item }}" insertafter="{{ header }}" with_items: ansible_all_ipv4_addresses - include: includes/launch-app pid_file="{{ pid }}" start_command="{{ agent_sh }} start" sudo_user: "{{ teamcity_user }}"