Questions tagged [ansible]

Use this tag for questions about Ansible, an open-source automation engine, related to using Ansible for topics such as cloud provisioning, configuration management, application deployment, etc.

Filter by
Sorted by
Tagged with
0
votes
1answer
327 views

Loop chmod with Ansible

I'd like to remove the execute bit from some ubuntu motd (Message of the day) files with ansible to disable some ad-like Ubuntu news. The module should only act if files exist and permissions are ...
2
votes
1answer
482 views

Looping through hosts from an inventory group in a group_vars file

Is it possible to do something like this: # inventories/inventory1/group_vars/group1 filewatches: {% for host in groups['group2'] %} - type: "copy" directory_name: "{{ host }}" ...
1
vote
1answer
85 views

Is it possible to have pair of IPs in Ansible?

I have so many HA machines that one of them is primary and the other is standby. I have this playbook that copies a config file from primary and then from standby on local machine then use those ...
2
votes
1answer
385 views

Share variables across instances

I'm writing TestInfra test scripts for mongo cluster instances using Molecule Ansible. I want to share variables across all the instances. I created a python class, and initialise and update the ...
1
vote
0answers
77 views

Per machine credentials for privileges escalation using AWX [duplicate]

I have an inventory with a lot of hosts in it using the same credentials, but one host needs a different approach. For the ssh connection a different user is used, after the connection is established, ...
0
votes
1answer
102 views

ansible error 'first argument must be string or compiled pattern'

I have this code in my playbook: - hosts: standby remote_user: root tasks: - name: replace hostname in config replace: path: /opt/agentd.conf regexp: #\s+Hostname\= ...
1
vote
1answer
334 views

Deploy Vm Vmware with simple Ansible playbook

I try to test one simple playbook with ansible. My goal is to create a new VM with it. --- # create a new VM from a template - name: VM from template hosts: localhost gather_facts: false ...
1
vote
1answer
3k views

Error passing arguments to ansible playbook

I am trying to create a playboook that executes a python3 script with 2 parameters, name and password in localhost. However, when i try to execute the paybook with this command ansible -b --become-...
1
vote
2answers
6k views

Waiting for privilege escalation prompt

I'm new with Ansible so hope to find answers here. I'm trying to run some playbook but getting an error: fatal: [10.65.30.117]: FAILED! => { "msg": "Timeout (12s) waiting for privilege ...
-1
votes
1answer
59 views

Ansible ec2_vpc_net and ec2_vpc_subnet - where to set subnet default public ip

Since upgrading to these 2 Ansible modules I am having difficulties in setting the subnets to have default public IP when new instances are created by autoscaling? I can't find any setting on the ...
1
vote
1answer
442 views

IOS_Command Module - Delayed Prompt Issue (Cisco 3850 - IOS XE)

I'm new to the Ansible world, so I'll do my best to explain everything. If I leave something out or need to clarify, just let me know. So, I've been working on upgrades for various Cisco switches/...
0
votes
1answer
388 views

Ansible - when statement task always return false value

I've got 1 master node from which I would like to instal NewRelic agents remotely depedning on the OS I have on them. Some of them are Amazon 2 Amis and some Amazon 1 Ami. I put when statement in the ...
0
votes
1answer
158 views

Ansible on Ubuntu Core

Ubuntu Core is a minimalistic operating system. It uses snap package manager instead of apt. Is it possible to manage a Ubuntu Core device with Ansible?
1
vote
2answers
91 views

Prevent misspelled variables passed to Ansible roles

I'm looking for strategies to mitigate silent errors related to misspelled or otherwise mistyped variables being passed to Ansible roles. So for example, I have a role with a defaults/main.yml: ...
1
vote
2answers
678 views

Ansible fetch all vars files from a directory to generate a combined vars file

What I'm looking for is a task (or tasks) to read whatever .yml files exist in a specified folder and combine them into a file containing all the variables. For example: pets/steves_pets.yml: cats: ...
1
vote
2answers
5k views

using copy module with wildcards

I need to copy a database backup file from a primary server to a standby server. Since I can't use synchronize, I was following this method: copy file to local ansible server from primary, then, copy ...
2
votes
2answers
100 views

reboot server during Ansible tasks

I have 3 scripts that must be run on server one by one. for example: - name: find config shell: /data/scripts/config1 become: yes become_user: root tags: find_config - name: change config ...
3
votes
3answers
2k views

What are some reasons for using an Ansible role for Certbot vs. Ansible's native `acme_certificate` module?

To get Let's Encrypt HTTPS certificates for their Web sites, I'm aware of quite a few folks using a particular role, which wraps Certbot, a standalone application not native to Ansible. There is, ...
0
votes
2answers
926 views

copy contents of file on ansible server to another file on remote servers

I have a bash script on about 70 severs in /opt/zservice/etc/config that i want to change its content with ansible. the new content is on ansible server in this path /data/new_config. how i can use ...
1
vote
2answers
77 views

Which Users Should I Create With Terraform And Which With Ansible?

I am creating some Ubuntu VMs in Azure with Terraform. I am then configuring the VMs with ansible. When terraform creates the VM it creates an admin user resource "azurerm_virtual_machine" "main" { ...
3
votes
1answer
6k views

Traverse nested dictionary with keeping the keys in ansible

I'm not able to loop a list in a dict and keep the key of the original dict. Bellow an example of my data vars: nginx_users: 'instance1': roles: - product - ...
1
vote
2answers
103 views

How to manage the versioning of Azure SQL Databases?

I am looking for a tool that will manage the versioning of Azure SQL Databases, and check for missing schema or migration scripts and apply those changes based on what is missing. Any other solutions ...
6
votes
1answer
2k views

Ansible: Exclude a parameter if variable is not set

Is there a way to exclude a parameter entirely if a variable is not set? I do not want to use a default value for this, I simply do not way the parameter referenced at all. For example, --- - name: ...
1
vote
2answers
2k views

Ansible nested playbooks with variables

I have an ansible playbook add_dns_record.yml that register the A record and relative PTR of an host to our MS DNS server. - hosts: my_ad_dns remote_user: "{{ lookup('env', 'USER') }}@MYDOMAIN.COM" ...
1
vote
1answer
234 views

Task to delete users without mount points in /home (using register and when)

I have a list of users that I want to delete (del_users), but I only want to delete those that haven't mountpoint on your /home directory. My currently code is: - name: Verify if exist mount point on ...
1
vote
1answer
606 views

Ansible equivalent of below sed command

How can i use ansible lineinfile module to simulate working of below sed command. sed -i _bkp '/(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.0.1)(PORT = 1501))/d;s/(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0....
1
vote
1answer
410 views

How to downgrade Jinja for Ansible?

I'm using Ansible 2.8.0 (ansible --version installed by brew on macOS) which is using Jinja 2.10. I've tried to downgrade Jinja to 2.8 via pip3 install jinja2==2.8, and I can confirm the right ...
5
votes
1answer
598 views

Is there any way of getting code coverage with molecule?

I'm currently working on testing Ansible roles with Molecule. I have one role with 2 scenarios that are executed in Jenkins but just before that, those are submitted to a SonarQube analysis. So I ...
0
votes
2answers
2k views

run ansible command as another user using their ssh key

i am trying to figure out how to run an ansible ping command as another user, using their ssh key. User setup i have essentially: master_user (me) ansible (sudo user, pwdless sign in) I logged in ...
0
votes
1answer
1k views

Ansible - stop when host is success, exit with IP

Basically, my use case is that I want to run on list of hosts (group from inventory). It will run one by one, until it finds machine answer my standards, when it find the one with free RAM as I say e....
2
votes
1answer
4k views

Ansible to check version of software on remote hosts before install/upgrade

Goal: Skip the host if version of custom software (non-rpm based) installed at remote host is greater than or equal to software version intended for upgrade. For all intents and purposes, this ...
2
votes
1answer
81 views

Preventing accidental production deployments

Last night I ran a playbook from a wrong branch that referenced an old inventory file with old IPs for each server, and deployed a dev build to a production machine. What would be a a good practice to ...
2
votes
3answers
1k views

Ansible playbook fails with: no test named 'success'

I have an Ansible Playbook that is used to configure WSL on my Windows Laptop, having rebuilt my laptop recently I needed to run the playbook again, however it is failing with the following message: ...
0
votes
1answer
208 views

how to give a user privilege to run Ansible commands or just an specific tag?

for example, I have a tag named 'installagent' and i want to run this command ansible -playbook -i /path agent.yml --tags installagent from another server via ssh on my Ansible server with user '...
0
votes
1answer
421 views

how to run an Ansible command for specific number of hosts

I am new to Ansible and i have a question about limitting hosts in a host group at running commands.I have these host groups in my inventory: [primary] host1 host2 [standby] host3 host4 ...
1
vote
1answer
80 views

How do I get the hosts from a specific section of an Ansible `hosts` file in a Jinja2 Template

I have a hosts file including the following contents [elasticsearch_nodes] host1 os=linux host2 os=linux host3 os=linux In a .j2 template I want to get the the list of [elasticsearch_nodes] {{ ...
3
votes
1answer
148 views

Configuration Management Tools and Rollbacks / Approaching Immutable Infrastructure

I am interested in whether there are any configuration management tools out there that make it easy to roll back. So far it seems that with Ansible, Chef, and Puppet you have to write the roll back ...
3
votes
1answer
3k views

passing args to shell module in Ansible adhoc command

Is it possible to pass args, to the shell module when running it as an adhoc command? I can pass the free_form parameter using -a, but I am trying to figure out how to specify additional arguments, ...
3
votes
1answer
780 views

Unable to run playbooks using Ansible best practices layout

I am very new to ansible and I think I am lacking something basic that I am not finding in the examples or on github as to the directory structure and its use. I have set up my directory structure ...
2
votes
2answers
243 views

Get Ansible to print lines for include_role(s)

I figured this would be trivial, but can't find the answer anywhere. Let's say I have a playbook.yml that looks like: - hosts: all tasks: - name: I'm a block! block: - name: I'm a role! ...
0
votes
1answer
104 views

ansible does not play roles and tasks

I'm learning ansible and I'm having a problem, when I run my playbook, it only runs the gather_fact task and does not play my roles. On the other hand when I run just a module with the ansible ...
1
vote
1answer
29 views

Ansible: Copying different files to different guests for use with the same role

I have a role, let's call it apache2. The role installs apache2 and all of its dependencies. Now I have two machines, let's call them M1 and M2. Both M1 and M2 need to have apache2 installed. However,...
1
vote
2answers
568 views

Ansible authorized copy from remote source to remote destination

How to use ansible authorized_key to authorize a ServerA (not the controller machine) to access Server B. Scenario: Need a playbook to execute from a ansible controller that should append id_rsa.pub ...
4
votes
1answer
1k views

Override Ansible task parameters from role

I'd like to be able to define a task with default parameters: - name: Create a new user user: name: "default" password: "password" state: present Then, from my playbook, I'd like to be ...
1
vote
2answers
81 views

Getting rid of redundant Ansible roles

I currently have a bunch of roles, like: apache2 gcc gedit ...etc. For each of those, I have a task file that looks like this: --- - name: "Install {{ role_name }}" become: true package: ...
2
votes
1answer
83 views

Structuring Ansible playbooks for low volume, purpose-built images

I hope this question is not too vague / opinion-based: I need to create and maintain a handful of virtual machines that get packaged up and deployed out to thousands of users, depending on specific ...
1
vote
1answer
721 views

Ansible cloudformation vs cloudformation

I would like to know the difference between - AWS cloudformation - Make AWS cloudformation template through Ansible (https://docs.ansible.com/ansible/latest/modules/cloudformation_module.html) I ...
0
votes
1answer
774 views

unable to save register value even if the play is skipped!

I have situation where i fetch some ip address on the fly with this play, when env variable is passed as prod, i have to fetch ip in a diff way then when i am in QA env. If env is prod the 1st play ...
2
votes
1answer
7k views

Looping through found files in Ansible

I am trying to set the sendmail_path to use Mailhog in all php.ini files on a server with multiple versions of PHP installed for PHP FPM. Why is the following snippet is not working? - hosts: ...
0
votes
1answer
803 views

Looking for Ansible equivalent method to yml Anchors, Aliases, when using include file

Using Ansible with the aci_rest module, requires the authentication parameters (hostname, username, password, method, validate_certs) to be defined in every task e.g. aci_rest: hostname: "{{ ...

1 2 3
4
5
8