Use ODL-managed ansible-odl repo in Packer builds
[integration/packaging.git] / packer / provision / config_ansible_fedora.sh
1 #!/usr/bin/env bash
2 # Install Ansible, as required for Packer's ansible-local provisioner.
3 # Also installs EPEL (dependency).
4
5 # Echo commands as they are run
6 set -x
7
8 # Install Ansible, required for Packer's ansible-local provisioner
9 # Git is required by the ansible-galaxy tool when installing roles
10 sudo dnf install -y ansible git python-dnf
11
12 # Install the latest release of ODL's Ansible role from Ansible Galaxy
13 # The `ansible-galaxy` tool was installed by Ansible's RPM
14 # NB: This could also be done by locally installing ODL's role, then
15 #     giving Packer it's local path via the role_paths argument to the
16 #     ansible-local provisioner. However, that approach requires a
17 #     step not managed by Packer (installing the role, which shouldn't
18 #     be checked into VCS, locally). Not only does that break the
19 #     model of being able to build directly from what's in VCS, it
20 #     breaks pushes to do automated remote builds. We can/should only
21 #     push what's version controlled, and we can't install the role
22 #     pre-build manually on the remote host, so we have to let Packer
23 #     own the ODL role install.
24 # NB: The simple `ansible-galaxy install <role>[,version]` syntax doesn't
25 #     support versions other than those on Ansible Galaxy, so tags. The
26 #     `ansible-galaxy` command will accept more complex versions via a
27 #     requirements.yml file, however. Using that to support branches,
28 #     commits, and tags. See: http://stackoverflow.com/a/30176625/1011749
29 # TODO: Pass this version var from packer_vars.json
30 ansible_version="origin/master"
31 cat > /tmp/requirements.yml << EOM
32 - name: opendaylight
33   src: git+https://git.opendaylight.org/gerrit/p/integration/packaging/ansible-opendaylight.git
34   version: $ansible_version
35 EOM
36 sudo ansible-galaxy install -r /tmp/requirements.yml
37
38 # Clean up to save space
39 # NB: The point of this script is to leave Ansible and ODL's role installed
40 #     and ready for use by the Packer Ansible provisioner, so we can't clean
41 #     up that space here. Need to clean it up in a post-install cleanup script.
42 sudo dnf remove -y git
43 sudo dnf clean all -y
44 sudo rm -rf /tmp/*