Below are a few additional tips for when writing your first few playbooks. These will show you some of the peculiarities of Ansible.
Installation is dependent upon the platform. For Unix-like systems you can use the package manager of the distribution and for Windows there is no package manager provided. Ansible has the chocolatey module, which is a package manager, that allows you to manage software automatically.
- name: install chocolatey win_chocolatey: name: - chocolatey - chocolatey-core.extension state: present
In general the
command modules, or
win_command for Windows respectively, should not be used as they are not able to use exception and error handling. Even though modules can do a lot, in some cases you must use the
There is very little difference between the
command modules. However the
shell module runs the command in a shell and therefore variables and operations like
| are available. On the other hand,
command is safer as it is not dependent on the host environment.
- name: npm install command: npm install /<path_to_app_dir>
There are a couple of options when trying to run a program. One of the options is to run an Ansible shell command. This runs the program in a shell, the same way you would do it from the command line of the device. However many programs have their own modules, which are usually easier to read for humans in the YAML files. If a program needs to keep running after the Ansible configuration, the
forever npm package can be used to prevent the program from stopping after the configuration. Other options do exist to keep software running.
- name: start PiCalc shell: forever start ./PiCalc/server.js