ansible

Ansible local_action directive

╄→尐↘猪︶ㄣ 提交于 2020-05-25 11:33:04
问题 I'm quite new to Ansible and have a simple question for my understanding of local_action directive. Would that mean that the command is fully executed locally? Let's say you have something like this: local_action: command which nginx register: check_nginx failed_when: no changed_when: no Then you have another block looking for nginx's existence with something like that: - fail: msg="nginx unavailable" when: check_nginx.rc == 1 Does that mean that playbook will fail in case nginx is not

Restart mutiple Docker Containers using Ansible not happening

倾然丶 夕夏残阳落幕 提交于 2020-05-17 06:58:46
问题 I am trying to restart my docker containers one by one for a particular image using Ansible but it doesn't seem to be happening. Below is my yml and what it is doing is exiting the current running container. --- - name: restart app servers hosts: shashank-VM connection: local become: yes become_method: sudo tasks: - name: Get info on the Container shell: docker ps | awk '/{{ item }}/{print $1}' register: list_of_containers with_items: - ubuntu - name: Restart Docker Service docker_container:

How do you output variables to Ansible? [duplicate]

ぃ、小莉子 提交于 2020-05-17 06:45:12
问题 This question already has answers here : How to pass terraform outputs variables into ansible as vars_files? (4 answers) Closed 7 days ago . I followed the answer here in this question and I have created a template file tf_ansible_vars_file.yml.tpl like below tf_share_location: "${share_location}" and a terra_render.tf like below # Define an Ansible var_file containing Terraform variable values data "template_file" "tf_ansible_vars_file" { template = "${file("/home/deployment_root/app4/tf

ansible include_role syntax problem although flow the documentions

老子叫甜甜 提交于 2020-05-17 06:00:28
问题 I try to include_rule but i keep getting errors on the wrong syntax this is my file structure : ├── roles │ └── utilities │ ├── defaults │ ├── files │ ├── handlers │ ├── meta │ ├── tasks │ │ └── d_pack.yml │ ├── templates │ └── vars └── test4.yml the rule d_pack.yml --- - name: Download package get_url: url_username: url_password: dest: url: owner: group: the test4.yml --- - name: check if exsist hosts: localhost gather_facts: false tasks: - debug: msg: "####################################

In Ansible/Jinja is there a way to regex_replace strings with integers using a dictionary of k:v pairs?

廉价感情. 提交于 2020-05-17 03:53:07
问题 NOTE: Original question expanded on here: Is there a way in Ansible to replace a dictionary value based on k:v lookup to another dictionary? I have 3 dictionaries, the first 2 are k:v with string:integer type values; My 3rd dictionary is a k:v of string:string which I want to loop through first with dict #1 and to replace the k with the k:v and then the same with dict #2 but replacing v with k:v. "dict_1": { "office-core01": 85, "office-core02": 86, "office-fw01": 87, "office-fw02": 88,

Ansible - Find using registered variable value

限于喜欢 提交于 2020-05-16 06:32:46
问题 What I am trying to achieve here is as below Unarchive the code from tar.gz - working Find file names in unarchived directory - working Find file names in code directory based on file names fetched in step 2 - failed Copy files from source:(Step 2) destination:(Step3) - working if I use the hardcoded file names in the pattern section of step 3 Below mentioned is the Ansible role I have used: - name: Unarchive config files to server unarchive: src: "{{ config_dir }}/config.tar.gz" dest: /tmp

Ansible Python API: how to pass extra vars to playbook

◇◆丶佛笑我妖孽 提交于 2020-05-15 05:34:07
问题 I'm trying to use Python API to run some playbooks because I want to integrate it with Flash to enable the web-base control. Here is my playbook( crondis.yaml ): - hosts: "{{app_name}}-server" tasks: - name: disable cron cron: name: "{{app_name|upper}}_MONITOR" job: "/{{app_name}}/monitor.sh" disabled: yes From cml that can be this way: ansible-playbook --extra-vars="{'app_name': 'newapp'}" crondis.yaml But in the Python API, I'm not seeing any place to add the vars to the play. I checked

shell-init: error retrieving current directory: getcwd — The usual fixes do not wor

喜夏-厌秋 提交于 2020-05-09 21:01:13
问题 I have a simple script: #!/bin/bash for server in $(~/.ansible/ansible_hosts) do ssh $server "hostname; readlink /opt/mydir/mylink;" done It works fine - the program returns the correct hostname and link - except that I get the following error on some but not all of the servers: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory All the directories exist. One of the most common suggestions has been to add a cd, a cd -, or a cd /

Difference between become and become_user in Ansible

我是研究僧i 提交于 2020-05-09 17:47:23
问题 Recently I started digging into Ansible and writing my own playbooks. However, I have a troubles with understanding difference between become and become_user . As I understand it become_user is something similar to su <username> , and become means something like sudo su or "perform all commands as a sudo user". But sometimes these two directives are mixed. Could you explain the correct meaning of them? 回答1: become_user defines the user which is being used for privilege escalation. become

Ansible: get current target host's IP address

夙愿已清 提交于 2020-05-09 17:44:48
问题 How do you get the current host's IP address in a role? I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address. You can get the hostname by using {{inventory_hostname}} and the group by using {{group_names}} I have tried things like {{ hostvars[{{ inventory_hostname }}]['ansible_ssh_host'] }} and ip="{{ hostvars.{{ inventory_hostname }}.ansible_ssh_host }}" 回答1: A list of all addresses is stored