Merge "xci: Add main playbooks and files"
[releng.git] / prototypes / xci / playbooks / configure-opnfvhost.yml
1 ---
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2017 Ericsson AB and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 - hosts: opnfv
11   remote_user: root
12   vars_files:
13     - ../var/{{ ansible_os_family }}.yml
14     - ../var/flavor-vars.yml
15   roles:
16     - role: remove-folders
17     - { role: clone-repository, project: "opnfv/releng", repo: "{{ OPNFV_RELENG_GIT_URL }}", dest: "{{ OPNFV_RELENG_PATH }}", version: "{{ OPNFV_RELENG_VERSION }}" }
18     - { role: clone-repository, project: "openstack/openstack-ansible", repo: "{{ OPENSTACK_OSA_GIT_URL }}", dest: "{{ OPENSTACK_OSA_PATH }}", version: "{{ OPENSTACK_OSA_VERSION }}" }
19   tasks:
20     - name: generate SSH keys
21       shell: ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
22       args:
23         creates: /root/.ssh/id_rsa
24     - name: fetch public key
25       fetch: src="/root/.ssh/id_rsa.pub" dest="/"
26     - name: copy flavor inventory
27       shell: "/bin/cp -rf {{XCI_FLAVOR_ANSIBLE_FILE_PATH}}/inventory {{OPNFV_RELENG_PATH}}/prototypes/xci/playbooks"
28     - name: copy flavor vars
29       shell: "/bin/cp -rf {{XCI_FLAVOR_ANSIBLE_FILE_PATH}}/flavor-vars.yml {{OPNFV_RELENG_PATH}}/prototypes/xci/var"
30     - name: copy openstack_deploy
31       shell: "/bin/cp -rf {{OPENSTACK_OSA_PATH}}/etc/openstack_deploy {{OPENSTACK_OSA_ETC_PATH}}"
32     - name: copy openstack_user_config.yml
33       shell: "/bin/cp -rf {{XCI_FLAVOR_ANSIBLE_FILE_PATH}}/openstack_user_config.yml {{OPENSTACK_OSA_ETC_PATH}}"
34     - name: copy user_variables.yml
35       shell: "/bin/cp -rf {{XCI_FLAVOR_ANSIBLE_FILE_PATH}}/user_variables.yml {{OPENSTACK_OSA_ETC_PATH}}"
36     - name: copy cinder.yml
37       shell: "/bin/cp -rf {{OPNFV_RELENG_PATH}}/prototypes/xci/file/cinder.yml {{OPENSTACK_OSA_ETC_PATH}}/env.d"
38     - name: bootstrap ansible on opnfv host
39       command: "/bin/bash ./scripts/bootstrap-ansible.sh"
40       args:
41         chdir: "{{OPENSTACK_OSA_PATH}}"
42     - name: generate password token
43       command: "python pw-token-gen.py --file {{OPENSTACK_OSA_ETC_PATH}}/user_secrets.yml"
44       args:
45         chdir: "{{OPENSTACK_OSA_PATH}}/scripts"
46     - name: copy OPNFV OpenStack playbook
47       shell: "/bin/cp -rf {{OPNFV_RELENG_PATH}}/prototypes/xci/file/setup-openstack.yml {{OPENSTACK_OSA_PATH}}/playbooks"
48     - name: copy OPNFV role requirements
49       shell: "/bin/cp -rf {{OPNFV_RELENG_PATH}}/prototypes/xci/file/ansible-role-requirements.yml {{OPENSTACK_OSA_PATH}}"
50     # TODO: this only works for ubuntu/xenial and need to be adjusted for other distros
51     # TODO: convert this into a role
52     - name: configure network for ubuntu xenial
53       template:
54         src: ../template/opnfv.interface.j2
55         dest: /etc/network/interfaces
56       notify:
57         - restart ubuntu xenial network service
58       when: ansible_distribution_release == "xenial"
59   handlers:
60     - name: restart ubuntu xenial network service
61       shell: "/sbin/ifconfig ens3 0 &&/sbin/ifdown -a && /sbin/ifup -a"
62 - hosts: localhost
63   remote_user: root
64   tasks:
65     - name: Generate authorized_keys
66       shell: "/bin/cat /opnfv/root/.ssh/id_rsa.pub >> ../file/authorized_keys"
67     - name: Append public keys to authorized_keys
68       shell: "/bin/cat /root/.ssh/id_rsa.pub >> ../file/authorized_keys"