Ansible: no hosts matched

You need to define a host inventory. The default path for this is /etc/ansible/hosts (as also stated by helloV). For a minimal example you can also specify an inventory in the command line: ansible-playbook setup.yml -i 192.168.10.1, The trailing comma makes it a list, such that ansible parses it directy. Otherwise you can run ansible-playbook … Read more

Conflicting action statement in ansible

Here is the problem, you have mixed up two tasks into one: — – hosts: webhost sudo: yes connection: ssh tasks: – name: debuging module shell: ps aux register: output – name: show the value of output debug: var=output And out put of the playbook will be like this: PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* … Read more

How can I manage keyring files in trusted.gpg.d with ansible playbook since apt-key is deprecated?

In short, you need to put the GPG key with the correct extension into a separate directory that is not searched by default, and point your repository configuration at that specific file. For more info on why you need a separate directory, see this answer to “Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d … Read more

How to compare kernel, software, etc. versions numbers in Ansible?

There is a version test for it: {{ ansible_distribution_version is version(‘12.04’, ‘>=’) }} {{ sample_version_var is version(‘1.0’, operator=”lt”, strict=True) }} Prior to Ansible 2.5, all tests were also provided as filters, so, the same was achievable with a filter, named version_compare, but in current versions of Ansible, the test was renamed and, overall, the tests … Read more

Copy a file with Ansible if it doesn’t exist

Assuming index.php exists in the role’s files subdirectory: – copy: src: index.php dest: /var/www/index.php force: no The decisive property is force. As the documentation explains, the default is yes, which will replace the remote file when contents are different than the source. If no, the file will only be transferred if the destination does not … Read more

System specific variables in ansible

Well you can set in three ways http://docs.ansible.com/intro_inventory.html#list-of-behavioral-inventory-parameters ansible_python_interpreter=/usr/bin/python2 this will set it per host Set it host_vars/ ansible_python_interpreter: “/usr/bin/python2” this will set it per host set it for all nodes in the file group_vars/all (you may need to create the directory group_vars and the file all) as ansible_python_interpreter: “/usr/bin/python2” Hope that helps

Formatting stdout in a debug task of Ansible

Try this option. You’ll love it. There’s a new YAML callback plugin introduced with Ansible 2.5 — meaning any machine running Ansible 2.5.0 or later can automatically start using this format without installing custom plugins. To use it, edit your ansible.cfg file (either globally, in /etc/ansible/ansible.cfg, or locally in your playbook/project), and add the following … Read more