Questions tagged [ansible-facts]

Use this tag for questions regarding Ansible facts - values discovered by the setup module of Ansible or pulled from ohai/facter.

768 questions
6
votes
2 answers

Ansible: Using ansible facts, how can I get a disk device based on the storage controller value and then set the device as a variable

Context: I have a system that has a combination of disks from different storage controllers, so each type of disk has different purpose. I'm new to ansible and learning as I go. Writing a playbook that gets the disk from each type of controller so I…
comet003
  • 63
  • 1
  • 1
  • 4
6
votes
1 answer

{{ ansible_hostname }} not working while calling directly with Ansible 2.3

Has anyone faced the following issue with "{{ ansible_hostname }}" while calling in a playbook task directly? Please suggest if there is other way around to do it or if I'm doing anything wrong here, I have tried it with both lineinfile & replace…
user7995721
6
votes
2 answers

Create set_fact variables in one role and use them in an other

I have a complicated environment with stages and users for multiple systems. The stages are: dev, int, etc. Each stage has a user for an application, let's call the user john. That leads to a user johnd for dev and johni for int and so on. To…
iamcheko
  • 111
  • 1
  • 1
  • 6
6
votes
2 answers

Amazon Linux machine - Ansible ansible_distribution* variables major release distribution

I'm using Ansible: 2.2.0.0 I have 3 machines: Two vagrant boxes (one CentOS 7.x and one Ubuntu 14.04) and 3rd box is an EC2 Amazon Linux instance (Amazon Linux AMI release 2016.03). On these boxes, I'm running the following command and getting…
AKS
  • 16,482
  • 43
  • 166
  • 258
6
votes
2 answers

Getting MAC address from Ansible facts in role

I'm trying to get the MAC address for the current host so that I can use the value in a task. Even after reading the docs I cant seem to wrap my head around how to do this. I've been trying to figure out the structure by dumping out the values. The…
RhythmicDevil
  • 705
  • 5
  • 15
  • 31
6
votes
1 answer

Use Ansible facts in an Ansible ad-hoc command

Is it possible to use what would normally be included in ansible_facts in an Ansible adhoc command? For example, I have a file at /tmp/myFile on all of my servers and I'd like to do: ansible all -i [inventory file] -m fetch -a "src=/tmp/myFile…
Mitch
  • 1,604
  • 4
  • 20
  • 36
5
votes
2 answers

Ansible pass fact between hosts in the same playbook

I'm trying to pass a fact from host1 to host2, but when ansible reaches hosts2 it returns "undefined variable": - name: some playbook gather_facts: false hosts: host1 tasks: - set_fact: fact1: "foo" - hosts: host2 gather_facts:…
Bugs Bunny
  • 365
  • 5
  • 19
5
votes
1 answer

What does Ansible return as `ansible_machine` and `ansible_architecture` under the Rosetta 2 emulation on M1 Mac

On a M1 MacBook, ansible_architecture and ansible_machine returns the same value that is arm64: shuuji3@momo mac-dev-playbook > ansible -m setup localhost | egrep '_architecture|_machine' "ansible_architecture": "arm64", …
shuuji3
  • 1,233
  • 13
  • 20
5
votes
1 answer

Ansible not gathering facts on tags

I'm habituated to use --tags when I'm using ansible-playbook to filter what tasks will be executed. I recently switched from Ansible 2.7 to 2.9 (huge gap, eh ?). I was surprised ansible did not gathering facts exclusively when I'm using --tags. And…
5
votes
1 answer

How to get ansible facts in lower case

I am gathering ansible facts . A serial number is coming in upper and lower case. see below. 5A2c32a-f1G85g-2035-0483-1fe9c129216d I need to compare that fact with another serial number which is in complete lower case.see…
sherri
  • 421
  • 2
  • 9
  • 19
5
votes
3 answers

Ansible: Remove item from dict

I have a situation where i am trying to remove the item from a list. but i am not getting expected result. Please help me what I am doing wrong here? here is the list : "get_ec2_id.instances[0].tags": { "Name": "test-db-system-2", …
Ankur Gupta
  • 143
  • 3
  • 11
5
votes
1 answer

Ansible get the value of the "hosts" key from an ansible play/playbook

Is there any way that I can get the group name for the set of hosts that a play is executing on? I know that ansible has a variable called ansible_play_hosts which is a list of all the hosts that a particular play is executing on. I want the actual…
Sami Badra
  • 111
  • 2
  • 6
5
votes
2 answers

Ansible - use fact from local host in remote host template

I have a playbook that contains roles for localhost and roles for remote hosts. In one of the localhost roles I set a fact called git_tag. I want to use this fact in a template for the remote hosts. I tried: - name: Read Version set_fact: …
Saar Kuriel
  • 572
  • 4
  • 16
5
votes
2 answers

Use facts gathered by ansible programmatically

I'd like to write a Python program that uses the facts that Ansible gives me with ansible HOST -m setup. When I call this, I get a response which makes it only almost pure JSON: $ ansible localhost -m setup localhost | success >> { // actual…
Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
4
votes
1 answer

Can't set ansible fact as integer

I am trying to extract the major distro version (which ansible_facts holds as a string) and store it as an integer for later < or > comparison to an integer. When I do this: set_fact: distromajor: "{{…
TSG
  • 4,242
  • 9
  • 61
  • 121
1 2
3
51 52