Questions tagged [ansible-playbook]

468 questions
2
votes
1 answer

How to use Ansible modules replace or inline instead shell command with SED

i have file with string: MYAPP.db.username.DEV=MYUSERNAME Where: MYAPP mean name of applications DEV means environment MYUSERNAME means name of user for connection to db I need to replace these variables according to variables, that i have in some…
Piduna
  • 541
  • 4
  • 12
  • 25
2
votes
1 answer

Ansible multiple hosts in one role

How do I write a single role and connect to different hosts as the script progresses? This is an example of what I would like to do, but I am getting an error as shown below. ERROR! no action detected in task. This often indicates a misspelled…
PrestonDocks
  • 215
  • 3
  • 11
2
votes
2 answers

How to display output of 2 commands in ansible?

--- - hosts: all gather_facts: false user: become: yes tasks: - name: Checking current kernel on Target Server shell: hostname;uname -r register: output - debug: msg= "{{ output.stdout }}"
vijdhanz
  • 21
  • 1
  • 2
2
votes
2 answers

Ansible using Having same host in multiple groups but while running playbooy even after specifying groupname its taking another groups variable

We have Apache setup chrooted, so we can multiple apache on single directory for multiple httpd instance. I have added all the different groups with the instance name in inventory but their hosts are same. While I am running tasks on one httpd…
blue_meme
  • 31
  • 1
  • 4
2
votes
0 answers

ansible block-rescue is not working with handler

I am trying the following playbook. But even after getting the error from handler, the rescue section is not working. handlers: - name: port status shell: netstat -nltp | grep {{ app1_port }} register: port listen: port_status - name:…
Sachin C
  • 21
  • 3
2
votes
2 answers

Ansible - delete all partitions on a given list of disks

I'm having serious trouble to do something that seems very trivial, I guess I'm probably going on the wrong way. The scenario is quite simple, I have a host_group in which I have a list of disks like: disks: "['sdb', 'sdc']" Then on a task I have:…
João Pereira
  • 39
  • 3
  • 7
2
votes
1 answer

Ansible: How to get a subelement of a nested list of dictionaries

I'd like to build our DNS zones via Ansible. The user should just maintain one variable for the forward-lookup zones (e.g. foo.bar). Reverse-lookup zones (0.0.10.in-appr.arpa) should be auto-generated with Ansible. The forward-lookup zone variable…
Mario Nette
  • 51
  • 1
  • 1
  • 7
2
votes
1 answer

ansible empty dictionary conditional

I had an error when I run this code: - set_fact: my_var: "{{ my_var|default({}) | combine( {item.key: item.value} ) | default({}) }}" with_dict: "{{ my_dict }}" when: my_id in authorised[item.key] FAILED! => {"failed": true, "msg": "The…
Henry TheKing
  • 99
  • 2
  • 3
  • 10
2
votes
1 answer

How to install mysql server using ansible playbook?

I am trying to install mysql server on centos using ansible playbook. My yml file looks like above. --- - name: Install MySQL database server hosts: test become: yes become_method: sudo gather_facts: true tags: [database] tasks: …
Janith
  • 223
  • 2
  • 4
  • 8
2
votes
1 answer

ansible -how to pickup hostname and create self signed certificate

i have working command for creating self signed certificate for IHS server's .kdb file and i was trying to use the same command through ansible. Here my aim is that ansible should detect the hostname of application servers and should use that name…
Vowner
  • 23
  • 1
  • 3
2
votes
2 answers

Ansible: user escalation failure

EDIT: This ansible_become_pass: "{{ scrappy.pass }}" #scrappy's password is the source of the problem. Should be password for ubuntu user I am having a hard time understanding how to set privileges per task in ansible. So given the playbook…
SavageSuga
  • 23
  • 7
2
votes
1 answer

Ansible - Using different users to login when working on a dynamic inventory

I'm trying to install a package on a list of servers, these have a tag in common so I'm using that tag as they are all having Environment tag set to Dev. But the issue is some of them have OS as Amazon Linux (login works with ec2-user), some of them…
2
votes
1 answer

Managing multiple remote user accounts and pubkeys with Ansible

I'm trying to work out a way to manage a single user's pubkey across multiple sites, as well as dropping that key into multiple $HOME directories. Reason being; our devs login as themselves to check on things, run sudo etc, however they deploy code…
Server Fault
  • 3,714
  • 12
  • 54
  • 89
2
votes
1 answer

Ansible: Replace (only) default config file

I'd like to place a custom configured /etc/my.cnf ONLY if the default my.conf is currently in place. Once the default my.cnf has been replaced or edited, I don't want to risk replacing it with my customized my.cnf. My best ideas, and the drawbacks…
Danny F
  • 498
  • 3
  • 10
2
votes
1 answer

Using if/else statement to run a command in shell

I wanted to run a command in shell (basically via ansible playbook), the condition is, if the ps status gives non zero exit code then it needs to run another command. I don't wanted to split this into two tasks, one to check the ps status and…