Questions tagged as ['ansible']

I need to make a playbook that will take a template file, interpolate some variables and put the resulting file to another directory.
The first part of the problem is that the resulting file will be used as another Ansible playbook, so the source file contains other interpolations and these interpolations must be preserved as they are. As an example, let's assume that the source file contains som ...
Team: I am trying to fail a task when two conditions are not met on a node. ansible_facts['distribution_version']
and ansible_facts['distribution']
.
I am passing in two nodes. one node is 20.x
ubuntu and other is 18.x
.
vars/main.yml
os_distribution: "Ubuntu"
os_version: "20.04"
task is below
- name: "Check Base OS Version maps to expected distribution version {{ os_version }}"
fail:
msg: "Task ...
I've been researching this for a while and it seems that installing an Oracle JDK rather than OpenJDK through Ansible is much more troublesome due to licensing from Oracle.
I've found some community solutions on Ansible Galaxy, namely these two:
azavea.ansible-java which isn't working due to a deprecated PPA repository the Ansible roles are using
ansiblebit.oracle-java which seems promising, however ...

I started to deploying an ansible server, and i was trying to create 5 users in the client hosts, through a playbook (add5userslist.yaml), with a loop that uses variables in a list from another file (userslist.yaml), but isnt working.
And...this is what ansible retrieves when i try to use this playbook with that list:
Seems like the problem is the list used in fact ansible doesnt even sees that as ...

I'm looking for help in merging two dictionaries in a specific way. I would be very grateful for any thoughts.
I have two dictionaries like this: 1st dict:
servers:
server1:
Property1: A
Property2: B
Property3: C
server2:
Property1: A
Property2: B
Property3: C
2nd dict:
management:
server1: ip1_addr
server2: ip2_addr
Desired result:
servers:
server1:
Property1 ...

I have two bellow tasks as part from my playbook
- name: "Verify httpd.service no running on node {{ ansible_hostname }}"
shell: "ps -ef | grep httpd"
register: _ps_httpd
become: true
- name: stop httpd is exit code eq to 0
shell: "kill -9 $(ps -ef | grep httpd| awk '{print $2}')"
when: _ps_httpd.rc == 0
become: true
ignore_errors: ...
I have some package added in yum exclude list in /etc/yum.conf and I want to remove a specific package from a exclude list
example:
exclude=java* exclude=kernel* java* exclude=java* kernel* exclude=kernel* abc* java* def*
I tried to add # but that do not serve the purpose and add comments to all exclude statement.
- name: Comment Java exclusion
replace:
path: /etc/yum.conf
regexp: '(.*ja ...
I'm facing a issue while executing shell script with ansible playbook.
Issue: I'm losing a connection with remote server because shell script is rebooting the server.
My Ansible playbook
- name: Handle reboot
hosts: all
become: yes
tasks:
- name: Execute the script
shell: bash testscript.sh
args:
chdir: /home/ubuntu
notify:
- Wait for server to restart
...
I would like to run mysqldump in the Ansible playbook by the shell module. Trying to find a way to hide my MySQL root password in the ansible playbook or Ubuntu.
I currently have a file that was encrypted by ansible-vault to store my mysql root password then I can call the password as a variable in the playbook. But I would like crontab to run my ansible-playbook every day. So it is impossible t ...

I want to create a var based on condition so I created the below :
hosts: test
vars: vtarget_backup_folder_in_progress: "{{ "{{ folder }}/{{ target }}/test{{ hostvars['localhost']['tstamp'].stdout }}{{ type }}" if node_type == "master" else "{{ folder }}/{{ target }}/prod{{ hostvars['localhost']['tstamp'].stdout }}_{{ type }}" }}"
but it fails with me with below error :
We could be wrong, but this one ...
I'm using the free version of Ansible at the moment. What is the maximum hosts a single Ansible controller can manage? I would assume it depends on the resources provisioned on the server but can't seem to find the docs for the free ver.
Also, in a segmented network like the example below (with a mix of Windows and Linux machines), I wasn't too sure but I assume that I need a controller for each ...

I have an ansible playbook which looks roughly like the following. I need Zero Downtime Upgrade start and Zero Downtime Upgrade completed steps. will run once to put\remove cluser into upgrade mode. in addition I need all the tasks into Block will be run only on one node on same time and continue to next node once we get HTTP 200
Could you please review the yml file ? currently I get ERROR! 'uri' ...
I have two sets of Linux VMs in a GCP (Google cloud) environment: Debian9 and RHEL8. The RHEL8 environment is FIPS-140 enabled, due to security/compliance requirements. None of our Ansible playbooks work with the FIPS-enabled RHEL VMs, but still work fine on the Debian VMs. The Linux control host is Debian9 as well.
For the failed RHEL8 playbooks , seeing this log in the Ansible playbook -vvvv ou ...

I have to create a new partition in a fresh disk on a VM. I use the parted module in order to create the partition. In a future task (in the same playbook), I need to use the UUID of the device partition (not the partition UUID, but the device UUID of the partition, present for example in /dev/disks/by-uuid/)
The problem is that : I don't find a way to get the UUID of the partition in a task afte ...

I have an ansible playbook which looks roughly like this:
- hosts: node1
tasks:
- name: get cluster state
shell: "RESTAPI 1 command"
- name: put cluster in upgrade mode
shell: "RESTAPI 2 command"
- hosts: node 1
tasks:
- name: upgrade Apache
shell: "upgrade Apache command"
- name: start Apache
shell: "start Apache command"
- hosts: ...

I'm trying to load dictionary variables from a file and can't access the variables inside. Could you please help me? sorry for so simple a question
Here is a working code example:
---
tasks:
- name: Dict test
vars:
users:
alice:
name: Alice Appleworth
telephone: 123-456-7890
bob:
name: Bob Bananarama
telephone: 987-654-3210
debu ...

so I have a couple raspberry pi's I'm trying to use as a cluster and I'm learning ansible to try and manage them easier. I'm running into an issue though. I can manually set the IP static using netctl but when I try to do it with ansible using the same exact commands I have issues. Also a weird note, the version that doesnt work, doesnt work on raspberry pi 4's but will work on raspberry pi b's.
...I'd like to split up some Jinja templating into multiple lines to keep lines under 120 characters, and register a variable for easy reuse. Is there a way to do something like the following? Is there a built-in (or community) module for this? If possible, I'd like to do it without using temporary files.
- jinja: "https://{{ username }}:{{ token }}@hosting.com/organization"
vars:
username: "{{ ...
Been trying to add a conditional with a wildcard and an Ansible variable and getting an error message. The idea is to trigger the api request with the container name starts with "android-", this is a follow-up to a docker container creation playbook.
My playbook:
---
- name: move agent android
hosts: server1; server2
vars:
containers: "{{ containers }}" #variable in a different file
tasks:
...

I try to run ansible-playbook from OSX that run this task and I'm getting the error bellow I tried to run 'Install Certificates.command' from Python folder but it didn't solve my problem.
fatal: [XXX]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "elapsed": 0, "msg": "Status code was -1 and not [200]: Request failed: <urlopen error [SSL: ...

Trying to set up graylog with official graylog2.graylog ansible role.
Installed Elasticsearch (v7.10.2) cluster on three separate servers with official elasticsearch ansible role (node_1 - master, node_2 and node_3 - data) - no problems so far.
When running graylog ansible (against another server) all is successful (including installation of MongoDB on the same graylog host), but restart of graylog-serve ...

The required azure files are in /home/ansible/.ansible/roles/azure.azure_modules/library/azure_rm_securitygroup.py
but ansible roles cannot find it.
cat azure_playbook.yaml
---
-
hosts: localhost
connection: local
gather_facts: false
roles:
- azure_vms
I get the following error:
TASK [azure_vms : Create Network Security Group that allows SSH] ************************************************ ...

Using Ansible 2.11.6 from Ubuntu. I have two Raspberry Pis in inventory
. One is an older Pi3 with Stretch; the other a Pi4 with Buster.
$ ansible -i inventory -m shell -a "df -h" all
shows the result of df -h
for both Pis, as expected. But
$ ansible-playbook -i inventory main.yml
where main.yml
is
---
- hosts: all
tasks:
- name: show disk space
shell:
cmd: df -h
after gathering f ...
I was not able to find anything on this after a lot of googling. All i could find were various kinds and ways of importing and including other tasks, but is it not possible to have two tasks in one file, and have one include the other - sort of like functions in most common programming languages? In my specific case i seem to need this to iterate over two lists at once - i tried including the name of th ...
Background: several parts of my host inventory are harvested automatically with the help of (many) scripts, mostly run out of cron. Many hosts have aliases (CNAMES, different network interfaces etc.) meaning that ssh host
brings you to the same machine as ssh host_alias
, and these aliases have a way to make it into the inventory and becoming immortal (because they pop up in several files) until m ...
- I fail with an Ansible playbook installing postgresql on a centos7 target due to some permission problem which seems to be rooted in selinunx in some way.
- As I have no experience with selinx whatsoever and am in process to learn ansible atm I want to get around this first without touching the question whether this is ideal or not from a selinux perspective.
So, I try to set selinux to permissive o ...
How can I filter the nocache
block or free
block using ad-hoc command? I tried ansible centos1 -m setup -a 'filter=ansible_memory_mb.nocache'
but doesn't filter it out.
ansible centos1 -m setup -a 'filter=ansible_memory_mb'
centos1 | SUCCESS => {
"ansible_facts": {
"ansible_memory_mb": {
"nocache": {
"free": 11808,
"used": 926
}, ...
So I'm running an ansible role which has a file main.yml in the defaults/ role folder. The content of that file is this:
---
api_secrets:
'API_PROFILE': "{{ api_profile }}"
'SERVER_ADDRESS': "{{ server_address }}"
'MGMT_SERVER_ADDRESS': "{{ management_server_address }}"
Now I want to include to the api_secrets block, after the MGMT_SERVER_ADDRESS something like this:
{% if '"port" in mgmt_port ...
I am trying to put together an Ansible environment that will accomplish the following...
- Provider version control for Ansible playbooks
- Automatically push approved pull requests to a mirror server
- Ansible server runs the playbook through the mirror (i.e. a proxy) to be executed on managed nodes
Reasons for this particular setup...
- The mirror already has access to all managed nodes
- The approved pl ...

I'm installing Percona Server 8.0 on Ubuntu using ansible, so it's non-interactive. I'm trying to run the post-install mysql_secure_installation
program, but that's not much good without interaction. Is there some way I can set its properties such as the default root password through an env var (which I've seen that percona server supports when running in docker) instead of interaction? Something alo ...