ansible-facts

How to store command output into array in Ansible?

人走茶凉 提交于 2019-11-30 15:23:48
问题 Essentially, I want to be able to handle "wildcard filenames" in Linux using ansible. In essence, this means using the ls command with part of a filename followed by an "*" so that it will list ONLY certain files. However, I cannot store the output properly in a variable as there will likely be more than one filename returned. Thus, I want to be able to store these results no matter how many there might be in an array during one task. I then want to be able to retrieve all of the results from

How to store command output into array in Ansible?

久未见 提交于 2019-11-30 14:21:10
Essentially, I want to be able to handle "wildcard filenames" in Linux using ansible. In essence, this means using the ls command with part of a filename followed by an "*" so that it will list ONLY certain files. However, I cannot store the output properly in a variable as there will likely be more than one filename returned. Thus, I want to be able to store these results no matter how many there might be in an array during one task. I then want to be able to retrieve all of the results from the array in a later task. Furthermore, since I don't know how many files might be returned, I cannot

Using facts from one host group to configure another host group with Ansible

人盡茶涼 提交于 2019-11-29 12:01:43
I am trying to configure one set of hosts [nodes] using facts from another set of hosts [etcd] . Here is my hosts file [master] kubernetes ansible_ssh_host=10.2.23.108 [nodes] n1 ansible_ssh_host=10.2.23.192 n2 ansible_ssh_host=10.2.23.47 [etcd] etcd01 ansible_ssh_host=10.2.23.11 etcd02 ansible_ssh_host=10.2.23.10 etcd03 ansible_ssh_host=10.2.23.9 Note that the group [etcd] is not the target of provisioning - [nodes] is. But provisioning [nodes] requires knowledge of the facts of [etcd] . Here is my playbook: --- - name: Configure common hosts: nodes sudo: True tasks: - name: etcd endpoints

Force fact-gathering on all hosts

爷,独闯天下 提交于 2019-11-29 05:31:18
I'm sitting in front of a fairly complex Ansible project that we're using to set up our local development environments (multiple VMs) and there's one role that uses the facts gathered by Ansible to set up the /etc/hosts file on every VM. Unfortunately, when you want to run the playbook for one host only (using the -limit parameter) the facts from the other hosts are (obviously) missing. Is there a way to force Ansible to gather facts on all hosts, even if you limit the playbook to one specific host? We tried to add a play to the playbook to gather facts from all hosts, but of course that also

How to filter gathering facts inside a playbook?

对着背影说爱祢 提交于 2019-11-28 21:31:54
I'm working on a role that only needs to gather a single fact. Performance it's a concern and I know that gathering facts it's time-consuming. I'm looking for some way to filter gather_facts inside a playbook, this will allow me to gather only the required facts. This is possible using the setup core module: ansible -m setup -a 'filter=ansible_hostname' my_host 10.200.0.127 | success >> { "ansible_facts": { "ansible_hostname": "my_host" }, "changed": false } It's possible to use this feature inside the playbook? Something like this? - hosts: all sudo: yes gather_facts: True filter: "filter

How to get an arbitrary remote user's home directory in Ansible?

妖精的绣舞 提交于 2019-11-28 15:29:15
问题 I can do that with shell using combination of getent and awk like this: getent passwd $user | awk -F: '{ print $6 }' For the reference, in Puppet I can use a custom fact, like this: require 'etc' Etc.passwd { |user| Facter.add("home_#{user.name}") do setcode do user.dir end end } which makes the user's home directory available as a home_<user name> fact. How do I get the home directory of an arbitrary remote user? 回答1: Ansible (from 1.4 onwards) already reveals environment variables for the

Using facts from one host group to configure another host group with Ansible

╄→гoц情女王★ 提交于 2019-11-28 05:15:19
问题 I am trying to configure one set of hosts [nodes] using facts from another set of hosts [etcd] . Here is my hosts file [master] kubernetes ansible_ssh_host=10.2.23.108 [nodes] n1 ansible_ssh_host=10.2.23.192 n2 ansible_ssh_host=10.2.23.47 [etcd] etcd01 ansible_ssh_host=10.2.23.11 etcd02 ansible_ssh_host=10.2.23.10 etcd03 ansible_ssh_host=10.2.23.9 Note that the group [etcd] is not the target of provisioning - [nodes] is. But provisioning [nodes] requires knowledge of the facts of [etcd] .

Where can I get a list of Ansible pre-defined variables?

…衆ロ難τιáo~ 提交于 2019-11-28 02:38:18
I see that Ansible provide some pre-defined variables that we can use in playbooks and template files. For example, the host ip address is ansible_eth0.ipv4.address. Googleing and searching the docs I cound't find a list of all available variables. Would someone list them for me? Argh! From the FAQ : How do I see a list of all of the ansible_ variables? Ansible by default gathers “facts” about the machines under management, and these facts can be accessed in Playbooks and in templates. To see a list of all of the facts that are available about a machine, you can run the “setup” module as an ad

Force fact-gathering on all hosts

。_饼干妹妹 提交于 2019-11-27 17:18:01
问题 I'm sitting in front of a fairly complex Ansible project that we're using to set up our local development environments (multiple VMs) and there's one role that uses the facts gathered by Ansible to set up the /etc/hosts file on every VM. Unfortunately, when you want to run the playbook for one host only (using the -limit parameter) the facts from the other hosts are (obviously) missing. Is there a way to force Ansible to gather facts on all hosts, even if you limit the playbook to one

How to filter gathering facts inside a playbook?

心已入冬 提交于 2019-11-27 13:53:00
问题 I'm working on a role that only needs to gather a single fact. Performance it's a concern and I know that gathering facts it's time-consuming. I'm looking for some way to filter gather_facts inside a playbook, this will allow me to gather only the required facts. This is possible using the setup core module: ansible -m setup -a 'filter=ansible_hostname' my_host 10.200.0.127 | success >> { "ansible_facts": { "ansible_hostname": "my_host" }, "changed": false } It's possible to use this feature