I need something like (ansible inventory file):
[example] 127.0.0.1 timezone="Europe/Amsterdam" locales="en_US","nl_NL"
However, ansible does not recognize 'locales' as a list.
You can define these variables in your playbooks, in your inventory, in re-usable files or roles, or at the command line. You can also create variables during a playbook run by registering the return value or values of a task as a new variable.
To try this playbook on servers from your inventory file, run ansible-playbook with the same connection arguments you've used before when running our first example. Again, we'll be using an inventory file named inventory and the sammy user to connect to the remote servers: ansible-playbook -i inventory playbook-02.
To define a variable in a playbook, simply use the keyword vars before writing your variables with indentation. To access the value of the variable, place it between the double curly braces enclosed with quotation marks. In the above playbook, the greeting variable is substituted by the value Hello world!
to use the command on a single IP/host not given in an inventory, invoke: ansible <ip> -m setup -i <ip>, - don't forget the comma at the end to make it a list and hence an inventory.
You can pass a list or object like this:
[example] 127.0.0.1 timezone="Europe/Amsterdam" locales='["en_US", "nl_NL"]'
With complex variables, it's best to define them in a host_vars file rather than in the inventory file, since host_vars files support YAML syntax.
Try creating a host_vars/127.0.0.1
file with the following content:
timezone: Europe/Amsterdam locales: - en_US - nl_NL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With