4

This blog post covers all of the methods: excerpt - Host names and patterns in Ansible 2 Inventory hostnames Ansible 2 requires inventory hostnames to be valid IPv4/IPv6 addresses or hostnames (i.e., x.example.com or x, but not x..example.com or x--). As an extension, it accepts Unicode word characters in hostname labels. Any mistakes result in ...


4

According to this best practices post, your file will look like this file: test [webservers] web1 web2 web3 [mysqlservers] db1 db2 db3 [lamp] lamp1 lamp2 lamp3 [misc] host1 host2 [all:children] misc webservers mysqlservers lamp [webservers:children] lamp [mysqlservers:children] lamp You can analyse your file by using ansible-inventory: ansible-...


3

Generally, Ansible is very flexible and often there are more "correct" solutions. Start for example with the question "Where do the configuration data come from?", put the default data to the roles and decide which variables should be configured in "group_vars/host_vars", in the roles, and which in the playbooks. Review Variable precedence: Where should I ...


2

It is a totally expected result. You define the same variables in different places and ansible applies its variable precedence First of all, remember that variables passed as extra vars always win: you can never change them in any other place or during the run (i.e. set_fact). Now let's decompose what happens. The schema is basically the same for all vars ...


1

The keyword hosts is missing. Also colons : are needed after the hostnames. Fix the syntax, for example all: children: control: hosts: moriarty.server.com: toby.server.com: managed: hosts: sherlock.server.com: See How to build your inventory.


1

The thing that makes this complicated is that ansible registers variables and facts locally, on the target remote host - and then has a different set of variables and facts once it moves to the next host. So it would require a bit of fiddling to do this exactly the way you want. One way to approach this would be to just use run_once, but it doesn't work ...


1

To append id_rsa.pub of a specific user from a remote ssh ServerA (no the controller machine ) to ServerB. 1) Fetch the public keys from ServerA - host: ServerA vars: public_keys_dir: <PUB_KEYS_DIR> specific_user: - user1 - user2 - userN tasks: - name: Fetch pub keys fetch: src: "/home/{{ item }}/.ssh/...


1

To solve this, I printed vars and ansible_facts, and eventually stumbled on the ansible_play_batch variable, which is a list of hostnames in the current batch. ansible_play_hosts_all gives the full list of hostnames. (Do not use ansible_play_hosts for this purpose, because as of Ansible 2.7, it works but the docs say it gives something completely different.) ...


1

It's in the wish list, I think. Quoting from the doc log_plays - write playbook output to log file * This callback writes playbook output to a file per host in the /var/log/ansible/hosts directory * TODO: make this configurable IMHO required functionality is not available at the moment. Take a look at the available plugins. "You can only have one plugin". ...


Only top voted, non community-wiki answers of a minimum length are eligible