Questions tagged [ansible]

1

votes
1

answer
2.8k

Views

ansible: check whether few lines are in some file and add them if not

UPDATE QUESTION: I am trying to validate that some function appears in .basrch file using ansible. I have tried lineinfile module: vars: bashrc: - name: my_func lines: - "my_func() {" - "echo name=username\n}" tasks: - name: add my_func() to .bashrc lineinfile: "dest=~/.bashrc regexp=\"{{ item.1 }}...
user1692261
0

votes
0

answer
4

Views

kolla ansible kubespray kube-apiserver connection refused (healthz error no 111)

I am trying to deploy kolla-ansible kubespray with 4 nodes: jumphost, controller, compute1, compute2 nodes. While executing deployment command: ansible-playbook -i inventory/ws/hosts.ini --become --become-user=root cluster.yml I got error of kube-apiserver connection refused. I attached also my host...
Khaled
0

votes
0

answer
6

Views

Why do my sudo commands work with ansible but not with ansible-playbook?

I'm experimenting with running Ansible scripts to set up Microsoft Azure VMs and for some reason I can run sudo commands through 'ansible', but can't run them through 'ansible-playbook'. As an example, I expect that the following command should fail without specifying the --become and --ask-become-p...
BackroomGibbon
2

votes
1

answer
88

Views

Tomcat8 failing to start in Ubuntu 16.04 in VirtualBox Vagrant on Windows Host

I'm not super familiar with vagrant and have an image for Ubuntu 16.04 with an ansible script that sets up and runs a tomcat8 server application. I went to set it up on a Windows host, and the tomcat service fails to start every time. The result of running the ansible playbook is: TASK [Restart tomc...
TJ_
0

votes
0

answer
4

Views

How to extend ansible playbooks to achieve complex conditions?

I understand that ansible is limited to being a configuration tool i.e., we create configurations in yaml files and python scripts does execution by looking at the configuration. There are howevever a useful attribute when that will help in deciding which configuration to be done based on the condit...
GP92
1

votes
2

answer
3.3k

Views

How to use the Ansible uri module to POST a file as form-data?

SonarQube allows the upload of a profile.xml file via form-data POST request as follows: curl -u admin:admin -X POST http://sonar:9000/qualityprofiles/restore -F [email protected] I'm trying to translate this curl command into Ansible, using the uri module. Unfortunately, I don't see any chance to...
dokaspar
1

votes
1

answer
1.9k

Views

Can I override Ansible SSH key inventory variable ansible_ssh_private_key_file on command line?

In Ansible 2.4.2.0, can I override the SSH key set in inventory with ansible_ssh_private_key_file on command line? It is not possible with --private-key option as reported on this issue: Command-line flags (variable weight) not respected (bug or a feature?) The inventory file: [group1] instance1 a...
apa64
1

votes
2

answer
1.3k

Views

Ansible - pip not found

I am getting this error: TASK [pip] ********************************************************************* failed: [default] (item=urllib3) => {"changed": false, "item": "urllib3", "msg": "Unable to find any of pip2, pip to use. pip needs to be installed."} Upon a suggestion I run following comman...
Eduardo
1

votes
2

answer
44

Views

How do I output with join()?

I want to output strings with join(). How could I use this? This is my code. data_list = [{'A': 'a', 'B': 'b', 'C': 'c'}, {'A': 'a', 'B': 'b', 'C': 'c'}] A_list = set() for data in data_list: A = data['A'] A_list.add(A) for A in A_list: B_list = [] C_list = [] for data in data_list: if data['A'] ==...
Lisa Go
0

votes
0

answer
8

Views

Is there any way we can run multiple roles with a particular user in Ansible

Is there any way we can run multiple roles with a particular sudo user using Ansible. If yes how can i do it . ansible 2.7.5
Sunit S Gaonkar
1

votes
1

answer
1.2k

Views

how to control the execution of rescue module in ansible

I have a playbook like this below ,i want to control execution of rescue when the block goes wrong。 I add when: is_debug is defined after rescue ,but when i run ansible-playbook dashboard.yml ,not give the is_debug value, the rescue is still excute when block has error . i want know how to cont...
qianwang
1

votes
2

answer
656

Views

CentOS 5. ansible_python_interpreter=/usr/bin/python26. Still cannot use yum: module

Still have to keep some CentOS5 hosts, they have yum configured to use CentOS vault repo like this https://hastebin.com/ojopevanas.ini. That works fine when use yum there on host. When however I try to use ansible for that, like: - name: "Install OS packages" yum: pkg={{item}} state=installed with_i...
Tag Wint
1

votes
0

answer
5

Views

Parsing XML with Namespace using Ansible, specifically a JBOSS standalone.xml

I am attempting to change values in a standalone-full.xml configuration file for a JBoss server. The issue I am running into is with the namespace. I have done several searches and tried several different scenarios, which I will provide. I know this has something to do with the namespace, because wh...
John
1

votes
1

answer
23

Views

How to check if dictionary key is null

I have json variable: "variable": { "changed": false, "data": null, "failed": false, "index": "135" } How to test if variable.data is null? I tried these, none works: when: variable.data is null when: variable.data is None when: variable.data is NoneType when: variable.data == 'None' when: variable....
BartBiczBoży
0

votes
0

answer
4

Views

ansible - create webhook for bitbucket repos

I want to write an ansible playbook using bit bucket rest api, which creates a webhook to trigger a jenkins pipeline with every merge. This is what I wrote: - name: create webhook for pipeline trigger uri: url: "{{ repo.location }}/webhooks" method: POST user: "{{username}}" password: "{{password}}"...
IrinaS
0

votes
0

answer
4

Views

Ansible — Using Conditionals from Ec2 Tags in Dynamic Inventory

I am using ec2 dynamic inventory. All of my ec2 instances are tagged with their environment. So for example tag:env = prod or tag:env = test So my dynamic inventory has variables set properly.... "ec2": [ "ip_10_1_1_1_ec2_internal", "ip_10_1_1_2_ec2_internal", "ip_10_1_1_3_ec2_internal", "ip_10_1_...
emmdee
0

votes
0

answer
3

Views

Adding a Ansible variable to Cassandra config template Yaml

I'm using Ansible to setup an AWS Cassandra cluster and I'm trying to pass the dynamic IPs to a YML template file. I have the IPs assigned to an Ansible group variable and want to use this when populating my Cassandra config YML. In Play 1 I initially assign the group like: file : roles/gather_cas...
MeanwhileInHell
1

votes
1

answer
9

Views

How can I use the mv module Ansible

I am trying to use the mv module on Ansible but I am not having luck. In my initial attempt I did the following: - name: changing the name of the file shell: mv /tmp/bundle /opt/Rocket.Chat And I get the following error: FAILED! => {"changed": true, "cmd": "mv /tmp/bundle /opt/Rocket.Chat", "delta":...
Marco Alfaro
1

votes
2

answer
2.8k

Views

“pause” for every host

Before rolling updates I want to set downtime for every host in our monitoring tool. I created a custom module for this. There might be problems when setting downtime which can not be fixed on our end. In that case I want to give the user the choice to decide if the deployment should be aborted or c...
udondan
1

votes
1

answer
4.9k

Views

Ansible: make output from a command become a key-value item/variable for the next command

I want to use this output (from a previous command) as an array of key-values or as an inventory for the next command in the same playbook stdout: hot-01: 10.100.0.101 hot-02: 10.100.0.102 hot-03: 10.100.0.103 .... hot-32: 10.100.0.132 like this: - shell: "echo {{ item.key }} has value {{ item.value...
ady8531
1

votes
1

answer
1.7k

Views

How to use nested variables (dictionary keys) in Ansible?

Feel free to suggest or directly edit my question if it's not expressed clearly. I have some nested variables declared in Ansible like this: # vars/main.yml parent_key: child_key1: "child_value1" child_key2: "Resolving: {{ child_key1 }}" But Ansible says: child_key1 not defined or something similar....
Neil
1

votes
2

answer
1.3k

Views

ansible playbook public keys issue

I've got this basic playbook that appends all the public keys located in the public_keys folder to the user's folder in .ssh/authorized_keys: - hosts: default vars: user: user1 tasks: - name: Set up authorized_keys for the user authorized_key: user={{ user }} key="{{ item }}" with_fileglob: - public...
miticoluis
1

votes
2

answer
5.2k

Views

[WARNING]: provided hosts list is empty, only localhost is available when inventory exists

I'm trying to get a list of facts available about my azure VM by running ansible -m setup hostname as described in the FAQ So I have ansible -m setup my-vm1 which I run from the machine in the azure cloud that I normally run my ansible commnads from (the machine I normally successfully use to talk t...
andrea
1

votes
1

answer
2.3k

Views

Aws passing credentials to ansible s3 module

In ansible,When I am passing the access key,secret key,token to my aws credentials,it passes the access key to my ansible module s3 ,but when I am passing secret key and token it shows me ""VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" like that.So how can I solve this. In accesskey id there is no extra spe...
jake
1

votes
1

answer
2.4k

Views

Ansible mysql grant

I want to grant privilege on a db(test_db) to a user(test_user) using Ansible. My command is as shown below. grant all PRIVILEGES on .* to @'localhost'; How will I execute the command using Ansible.
Pattu
1

votes
2

answer
3.4k

Views

Ansible & Jinja2: combine a dictionary to each element of a list

I have a variable that is an array [{'foo':1},{'bar':2}]. I want to combine it with the following hash: {'baz':3} using a set fact (?) such as my output registered variable is: [{'foo':1, 'baz':3},{'bar':2, 'baz':3}] I've looked into the combine filter, but it only works when I already have an hash...
Stephane
1

votes
0

answer
5

Views

Ansible: Extract value from json array

I've run this command to get all the Internet Gateways in my AWS account with the tag value prefix of 'myVar_igw_'. My aim is to extract the tag value from the output. - name: IGW Facts ec2_vpc_igw_facts: region: "eu-west-2" filters: tag:myVar: "myVar_igw_*" register: igw_facts Outputting the igw_fa...
Danzaa
1

votes
2

answer
977

Views

Ansible update still shows old version

I upgraded ansible from version 2.0 to 2.3.1 on a Debian 8 server and followed the instructions that Ansible provided: Add to Sources list: deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main Run Following Commands: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7B...
ryekayo
1

votes
1

answer
2.4k

Views

Ansible logging

I am having difficulty getting Ansible to perform logging. A simple YAML named demo5.yml spins up AWS EC2 instances (below). The following entry has been added into the ansible.cfg file: log_pth=/var/log/ansible.log The playbook YAML is executed by calling: ansible-playbook demo5.yml -v There is not...
Backwardation25
1

votes
1

answer
749

Views

Execute background process from Ansible

Ansible runs processing using SSH. Therefore, it is not possible to start the background process. Is there a solution to start background processes with Ansible? Thank you.
Kun Ns
1

votes
0

answer
61

Views

Possible to test dynamic ansible variables with testinfra/pytest

I am using testinfra/pytest to test my ansible variables with: vars.yml FRUIT: "apple" IS_APPLE: '{{ FRUIT == "apple"}}' test.py import pytest @pytest.fixture() def AnsibleVars(host): ansible_vars = host.ansible("include_vars", "file=vars.yml") return ansible_vars["ansible_facts"] def test_vars(Ansi...
u123
0

votes
0

answer
4

Views

Trying to build playbook for install airflow (On virtualenv folder). Ansible not executing commands inside the virtualenv environment

Trying to build playbook which can install apache-ariflow on virtualenv environment. Ansible not executing commands inside the virtualenv folder. Below is the my playbook and error. Playbook Content :- - name: Active virtual Environment shell: source bin/activate args: chdir: "{{ directory }}" - nam...
Balaji Mungal
1

votes
1

answer
96

Views

Update Password if user exist Ansible

Im new on Ansible and i try to create some user accounts on remote servers and i encountered some trouble. I want to create users if they do not exist, and update them password if they are present. I read the documentation and found the parameter "update_password" but im stuck on how to verify thei...
HastEd
1

votes
2

answer
55

Views

Parsing value from non-trivial JSON using Ansibles uri module

I have this (in the example shown I reduced it by removing many lines) non-trivial JSON retrieved from a Spark server: { "spark.worker.cleanup.enabled": true, "spark.worker.ui.retainedDrivers": 50, "spark.worker.cleanup.appDataTtl": 7200, "fusion.spark.worker.webui.port": 8082, "fusion.spark.worker....
Marged
1

votes
2

answer
41

Views

clone Git Repository

I wrote an ansible playbook which creates a new BitBucket repository. Now I want to configure the repository according to the instructions shown under the repository source in BitBucket: You have an empty repository To get started you will need to run these commands in your terminal. New to Git? Lea...
IrinaS
1

votes
2

answer
43

Views

If else in ansible print statement

I would like some help with syntax for a print statment that has multiple conditions. Currently, the quotes for '{{inventory_hostname}}' is causing errors and if I remove the quotes the playbook runs but lists the text inventory_hostname instead of the variable. I would like know how I can get the v...
techkid
1

votes
1

answer
12

Views

Ansible linefile module's attribute line is not adding environmental variable on server

Hi I am having a task which is as follows - name: Replace log directory in configuration lineinfile: path: $HOME/amsible_test/test.txt regexp: '^dataDir=' line: 'dataDir=$HOME/.zookeeper_log' it's running fine , But issue is that this is writing line as dataDir=$HOME/.zookeeper_log but as per my...
Pankaj Cheema
0

votes
2

answer
21

Views

Is ansible compatible with Ubuntu 18.04? [on hold]

I am trying to run small playbook over Ubuntu 18.04 virtual machine and facing the issue while it gathers the facts. PLAY [all] ****************************************************************************************************************************************************************************...
srinivas ga
0

votes
0

answer
3

Views

In an Ansible playbook, what is a better way to iterate over a list of objects and call a different role depending on that object's data?

I am using Ansible to read in a YAML file containing a list of dictionaries. I then need to iterate through this list and call a different role depending on data within each list object. I have a solution that is working, but it seems so kludgy to me, that I wanted to find out if there was a better...
Kris
1

votes
2

answer
1.5k

Views

how can i pass the parameter as “integer” in ansible?

so i have this piece of yaml in my ansible project. - name: common | register vim as a type of editor for update-alternatives command: update-alternatives --install "/usr/bin/editor" "editor" $(which vim) 100 sudo: yes What I want to do is to register as a kind of editor, set the priority to 100. as...
Ya Zhuang

View additional questions