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

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.


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 ...


2

The hostnames parameter controls what the plugin uses as the host name. It accepts a list of attributes, and will use the first one that the instance has defined: hostnames: - private-dns-name - private-ip-address You can also set the ansible_host variable using compose. This changes the connection target without modifying the inventory hostname: ...


2

The answer is in the warning you get: [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' When you use hosts: all in your playbook, localhost is not matched. If you want to run the playbook on localhost, you can do one of the following: Change your playbook to hosts: localhost. ...


2

This error is due to invalid value of ansible_network_os: The playbook you try setup is meant for network devices. And since centos is not a network device OS the playbook will fail. Here you can find supported network OS. Ansible Documentation: ansible_network_os values If you don't have any device running a supported network OS I recommend you to follow ...


2

The simple answer is "yes" you can use Ansible for monitoring configuration, but you will have to do some extra work. As Vasily stated in their answer, Ansible does not have a built in triggering mechanism, so you need something to trigger the convergence of state. This can be done in several ways, the easiest being probably ansible-pull. As the ...


2

Q: "Does the hosts: all pattern only match hosts specified in inventory, or does it also match add_host hosts?" A: Simple test shows hosts: all includes also added hosts by add_host. In the same playbook, of course. The dynamic groups live inside a playbook only. Given the inventory shell> cat hosts host1 host2 The playbook --- - name: Only 2 ...


1

Do the following for each Vagrant machine you want Ansible to work with...in this example, using the machine master1: Do vagrant ssh-config > vagrant-ssh Enter content from vagrant-ssh into your ~/.ssh/config, modifying it as needed, like this example for some machine named master1: Host master1 HostName 127.0.0.1 User vagrant Port 2222 ...


1

While I haven't worked with plugin: aws_ec2, here's some general Ansible information that might help you: The order of inventory files matter; the files given first will be read first; the ones read last will take precedence. In your execution, you're referencing secrets.yaml last, so when aws_ec2.yaml is read, the secrets are still undefined. You're trying ...


1

Just add hosts before every block of hosts. I.e., under the group level, you should have hosts directive See ansible source code example: - Hosts must be specified in a group's hosts: Working inventory.yml: all: children: control: hosts: localhost 127.0.0.1 managed: hosts: localhost


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