Questions tagged [ansible]

Ansible is an automation tool ("IT orchestration engine", per the company web site) for the deployment and configuration of applications and systems.

Filter by
Sorted by
Tagged with
24
votes
1answer
20k views

ansible extract without first directory

When extracting a tar.gz file in ansible I end up with a first directory - name: Extract archive unarchive: src=file.tar.gz dest=/foo/bar which results in /foo/bar/bar-version-...
24
votes
1answer
21k views

Proper syntax for ansible symlink

What is the proper syntax for creating symlinks using ansible? I'm creating a Vagrant virtual environment and running ansible as my provisioner. Everything works fine up until I try to symlink to my ...
23
votes
3answers
60k views

List ALL Ansible variables for a host or group with an ad hoc command?

Ansible variables come from a variety of sources. It is for example possible to provide host_vars and group_vars by creating YAML files in a subfolder named host_vars and group_vars respectively of ...
15
votes
2answers
78k views

Ansible use inventory_hostname or ansible_hostname in task name

I am writing a rolling upgrade playbook and would like to print out the hostname of current host been upgraded. I put inventory_hostname and ansible_hostname in task names but that did not work - ...
11
votes
2answers
27k views

How would I register a dynamically named variable in an Ansible task?

I'm trying to retrieve the group ID of two groups (syslog and utmp) by name using an Ansible task. For testing purposes I have created a playbook to retrieve the information from the Ansible host ...
8
votes
4answers
914 views

Is there a distro-agnostic configuration management software?

I don't want to label myself to specific configuration-manager modules like Ansible's apt module or yum module. Is there a distro-agnostic configuration management software, or at least one with ...
8
votes
1answer
16k views

How can install specific version of ansible?

How can I install a specific version of Ansible, using Yum or another method? When I try to install version 2.0 it says No package 2.0 available. I checked the epel repo. There are only two rpms, ...
8
votes
2answers
1k views

Whenever ansible makes changes to sshd in CentOS7 a random future play cannot connect

This has been an irritating enough problem now that I thought I would finally ask the community at large what a possible solution might be. It's even more irritating that I seem to be the only one ...
7
votes
1answer
557 views

How do I open a file with ansible-vault edit from inside vim?

Usually, when I want to open a file encrypted by ansible-vault for editing, I just run ansible-vault edit <filename> - this decrypts the file to a temporary file and opens it for editing. ...
7
votes
1answer
513 views

Configuration management via versioned packages

For the hosts we manage, my boss has a vision of configuration management via versioned packages (in our particular case, fpm-built debian packages). This is to make: host deployment easier easier to ...
5
votes
2answers
3k views

Can I automatically accept MS SQL license terms while installing the yum package?

I am using Ansible to provision MS SQL Server 2017 to a CentOS 7.4 box. I first went through this guide via command line and it works, but my end goal is to "Ansible-ize" it. However, when I get to ...
5
votes
1answer
439 views

Turn off color in bash for logs

I am running Ansible on multiple machines and redirecting the output to a file, say log-$(date), which is mailed to me every day. The output file has multiple text colors, how to turn them off? ...
5
votes
2answers
12k views

Ansible failed_when only print customized error message

I am writing a simple Ansible playbook to run RHEL leap second detector on Linux boxes with mixed distribution. here is the playbook --- - hosts: Linux vars_files: - ../group_vars/Linux.yml ...
4
votes
1answer
18k views

Unarchiving a downloaded tarball with Ansible

I'm trying to get WordPress downloaded and installed via Ansible and I can't seem to figure out what I'm doing wrong here. First I download via the get_url module then I attempt to use the unarchive ...
4
votes
1answer
5k views

Terminate and disable/remove unattended upgrade before command returns

I'm having an issue here where I try to automate a setup with Ansible. Some of the steps require interaction with apt, but occasionally I get an error because unattended-upgrade kicked off and locked ...
4
votes
2answers
23k views

Add user and set password using Ansible

I have created an Ansible playbook to create user and set password. But it is giving me an error ERROR: password is not a legal parameter of an Ansible Play --- - hosts: all user: root vars: ...
4
votes
1answer
647 views

ansible.cfg become_ask_pass not working

I am using Ansible 2.5.1., and I do not want to use the flag -K all the time (I think it will be deprecated soon). I know there is a directive of become_ask_pass in the ansible.cfg file. I set this ...
4
votes
1answer
3k views

Ansible - How to mark a tasks as success when it failed actually

We are using some pipelines to build servers using ansible and one of the task is to check if server is online (means a production server in inventory list by accident). We check the port 443 and ...
4
votes
1answer
2k views

read a file and execute each line as command using ansible

I want to write a playbook for following scenario: reads a text file which has linux commands written it, executes them one by one, aborts if any command fails to execute, and if I correct the command ...
4
votes
1answer
942 views

How do I install jdk on SUSE Linux with ansible?

I need to install java on one of my VMs running SUSE Linux using ansible. Below is the playbook code I am using: - name: Download Java become_user: "{{user}}" command: "wget -q -O {{java_archive}...
4
votes
0answers
976 views

Ansible play for creating user not setting password

Try to set a password randomly and create user with it: vars: users: - username: myuser password: "{{ 99999999999999 | random | to_uuid }}" role: - name : Add user accounts user: name: ...
3
votes
2answers
8k views

Ansible: How to parse an inventory source

I'm following an Ansible tutorial I got from Packt, I reached this part where I've created 3 Ubuntu containers (lxc) and got them up and running. I'm also able to login to each of them. I've ...
3
votes
1answer
7k views

How to ignore a particular output error string in Ansible and consider successful

I'm trying to ignore a particular error message in playbook output is having below error message. fatal: [192.168.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "Sending passwords in ...
3
votes
1answer
402 views

with CentOS 6.x minimal install I cannot start iptables

I'm currently working on a Ansible playbook that attempts to install and start the iptables firewall on a CentOS 6.8 minimal install. I'm doing the following in Ansible. ### sets up FW pkgs - name: ...
3
votes
1answer
5k views

The destination directory (/etc) is not writable by the current user on ansible

I am using Ansible-2.0 on linux machine and I wish to do change DNS on remote machine using ansible as below: --- # tasks file for test - name: Change dns become: yes become_user: admin ...
3
votes
1answer
970 views

What Command Line tools to connect from Unix to remote Windows?

I need to make some scripts for connecting from a Unix server to several Windows stations for automating file transfers. GUI is not needed and I can't install any additional software into Windows ...
3
votes
1answer
11k views

Ansible result.failed v.s. failed_when, result.changed v.s. changed_when etc

Ansible in 1.4 and later provides a way to specify this behavior as follows: - name: Fail task when the command error output prints FAILED command: /usr/bin/example-command -x -y -z register: ...
3
votes
0answers
716 views

using ansible via vpn

I have a set of hosts that I can only access via openVPN (one VPN per host or group of hosts). ssh is only available after connected to the VPN. Is there any way to automatically bring up the VPN ...
3
votes
0answers
2k views

start-stop-daemon, services, environment variables, and ansible

So, I have a Java program that runs Ansible. I'd like to run this program as a service. I've written a service script in /etc/init.d that uses start-stop-daemon to run/stop the Java program. I've run ...
2
votes
3answers
2k views

Using /dev/stdin and a heredoc to pass a file from the command line

I'm curious about the theory behind how heredocs can be passed as a file to a command line utility. Recently, I discovered I can pass a file as heredoc. For example: awk '{ split($0, arr, " "); ...
2
votes
2answers
165 views

Encrypt a file on remote host

How to encrypt a file on the remote host using Ad-Hoc command 'ansible-vault'. for example, a myfile.txt on a remote machine needs to be encrypted from the host machine
2
votes
3answers
3k views

Is it possible to start administering a linux box via Ansible with just the root account and its password?

I recently rented a Linux box and I intend to provision it using Ansible. I'd like to use Ansible as early as possible in the process. At this stage I only have a root account and the corresponding ...
2
votes
1answer
1k views

yum lockfile is held by another user

Amazon Linux 2 instances are operated upon by an Ansible Playbook which performs multiple yum tasks one after the other. What specific changes need to be made to the syntax below in order for the ...
2
votes
1answer
6k views

When I use ansible module expect, I get this msg: The pexpect python module is required

Some code from yml file: - name: --- run /opt/installer/bin/install.sh --- expect: command: /opt/installer/bin/install.sh responses: 'Are you installing the application at the ...
2
votes
1answer
605 views

inserting data into a particular section of a configuration file with ansible

I have come across a peculiar issue while using ansible. The problem is very strange and dangerous. I have a written a code to insert data in a particular section of a file i.e to add line after [...
2
votes
1answer
4k views

In Ansible dynamic inventory JSON, can I “render” hostvars based on the hostname?

The Ansible documentation gives an example here on how to return an inventory in JSON format: { "databases" : { "hosts" : [ "host1.example.com", "host2.example.com" ], "vars" ...
2
votes
2answers
179 views

How to enable or disable Apache modules in a distro-agnostic way?

I usually work with Debian/Ubuntu as a basis for Apache and recently learned that commands like a2enmod MOD or a2dismod MOD are Debian-specific. Is there a global / distro-agnostic way (maybe with ...
2
votes
1answer
179 views

Is it a best practice to use Ansible-Galaxy roles in playbooks instead ansible-modules in playbooks? [closed]

I have an Ansible playbook for establishing LAMP environments on remote machines. Part of this playbook deals with installing Composer: - name: Install Composer get_url: url: https://...
2
votes
2answers
69 views

Using a if/else statement in shell for netsat

My goal is to ensure that email connections are limited to outbound only So I have two shell commands one is netstat -an | grep ':25' | grep -v '127.0.0.1' | wc -l which prints out 1 The command ...
2
votes
1answer
3k views

How do you set up a confirmation prompt before running a playbook?

I want to install MariaDB after confirming user. I have a role and one simple task: - name: install MariaDB yum: name: MariaDB state: present or if I want to use include: MySQL.yml, if the user ...
2
votes
1answer
24 views

Is it possible to define run_once strategy on Ansible?

I would like to run a task only on one host with Ansible. To do that, I use the parameter run_once. But what would really rock is to be able to specify a strategy to select that one host to run that ...
2
votes
1answer
654 views

What is the best way to share the SSH authentication socket with another user?

I'm using Ansible for setting up a remote server and I'm using SSH agent forwarding to git clone a repository from bitbucket.org to use my local SSH key, because I'm using sudo I'm preserving the ...
2
votes
1answer
3k views

Can I view tasks that will be run by ansible-playbook?

Can I review tasks that would be run by ansible-playbook? ansible-playbook --check does not list all tasks. Tasks which depend on previous tasks being performed may fail, causing ansible to stop ...
2
votes
1answer
5k views

How to Bind Mount /var/tmp to /tmp using Ansible and to CIS standards

I am hardening a centos6.7 VM to CIS benchmark standards. I am automating as much as I can using Ansible. The hardening document I am using is (page 12-13): https://benchmarks.cisecurity.org/tools2/...
2
votes
1answer
4k views

Bash script and yml file output

I'm trying to catch the stdout of a script to a file, and at the same time have it display its ongoing summary: ./RUN host-names ANSIBLE.yml 2>&1 | tee out.txt What this does is that it ...
2
votes
1answer
1k views

Ansible command returns change instead of success

I'm learning ansible and encountered a situation which is not clear. Running the following module command the result is a 'Changed'. ansible agent.example.com -i inventory -m copy -a 'content="Node ...
2
votes
1answer
152 views

Clarification on example from Ansible documentation needed

The lxd_container module for Ansible 2.5 contains this example: # An example for creating a Ubuntu container and install python - hosts: localhost connection: local tasks: - name: Create a ...
2
votes
1answer
461 views

Ansible shell module empty response

When i execute the command "who am i" using ansible's shell module, i get an empty response, i can't figure out why ? hosts: server1 remote_user: devops become: true tasks: - name: print ...
2
votes
1answer
368 views

Ansible Task Creates option issue

I want to write an Ansible playbook to install a package only if a particular is not present, so when the /tmp/hosted file present installation should not proceed, but it's failing: --- - hosts: all ...
2
votes
1answer
2k views

Configure Ansible to write logs to a different file on managed servers

I would like to know if there is a way to configure Ansible to have its own log files instead of writing to /var/log/messages on RHEL server.