Score:0

Ansible conditional file placement

lu flag

How do I perform the following with Ansible playbook. I'm new to it. Thanks!

File example that contains the hostname and password

{ 
  "hosts":[
  {
      "node": "node1",
      "pass": "pass1"
  },
  {
      "node": "node2",
      "pass": "pass2"
  }
]}

I need to put file.txt on each server with their respected values.

Example, On node 1 the file.txt should contain the node name "node1" and password "pass1"

Michael Hampton avatar
cz flag
Is this file from some external source? Otherwise you would normally put such things in ansible host variables and use a template.
user772543 avatar
lu flag
It's a local file on the ansible server. I don't want to use host variables since it contains passwords. I also need only place the file (file.txt) once on servers then run an external command then remove the file.
Michael Hampton avatar
cz flag
You are familiar with Ansible Vault, yes? If it's a local file, is it not encrypted as Vault would do?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.