1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
Preparing a development environment
===================================
In this guide, we will go through the process of setting up a development
environment.
Prerequisites
-------------
There are a few things we will need to have installed on our workstation. They
are, in no particular order:
* a python 3 interpreter with virtual environment support,
* ``git`` tools,
* a functioning docker installation (for integration tests), and
* SELinux python bindings (only on systems with SELinux installed).
It should be relatively straightforward to get those things installed on our
machine. Once we have them ready, we can start customizing our environment for
Ansible development.
Obtaining the source code
-------------------------
Sensu Go Ansible collection lives on GitHub, which means that we are just one
command away from the full source code. But before we can clone the
repository, we need to create a few directories that will hold the source
code::
$ mkdir -p ansible_collections/sensu
$ cd ansible_collections/sensu
$ git clone git@github.com:sensu/sensu-go-ansible.git sensu_go
$ cd sensu_go
.. note::
It is vitally important that we
1. create two parent directories before checking out the code, and
2. that we clone the code into the `sensu_go` directory.
Ansible development tools often assume that we are working from the
``ansible_collections/<namespace>/<collection>`` directory and complain
loudly if they do not have it their way.
And this is it.
Installing development tools
----------------------------
The first thing we need to do is create a new virtual environment and activate
it. ::
$ python3 -m venv ../../../venv
$ . ../../../venv/bin/activate
.. note::
We intentionally created our virtual environment outside the collection
directory. This is a simple way of making sure that various static analysis
tools only report issues with our code and not with any of the
dependencies.
Now we need to install Ansible. Since we are just starting, latest stable
version will do just fine::
(venv) $ pip install ansible
All that separates us now from the fully functioning development environment
are a few dependencies. We can install them by running the next command::
(venv) $ make requirements
There is just one more thing left for us to do: test the setup.
Testing the setup
-----------------
To validate our setup, we can run the bundled tests and render the
documentation::
(venv) $ make sanity
(venv) $ make units
(venv) $ make docs
(venv) $ make -j4 integration
We may want to go grab a cup of tea after running that last command, since it
will take a while (about fifteen minutes on a semi-decent development
machine). And if all of the commands finished with no errors, we are ready to
start developing.
|