ansible

When running an ansible playbook via a shell script in Jenkins pipeline, the echo output is buffered and does not show in real time

吃可爱长大的小学妹 提交于 2021-01-28 20:00:53
问题 So below I have attached my pipeline code for Jenkins. The runansible.sh script takes in the parameters given and then proceeds to run an ansible playbook based on the paramMode value. When kicking off the shell script in a terminal I get realtime output of the ansible playbook running, but when using the Jenkins pipeline I just get the loading cogwheel during the echo stage. I do not get any echo output until the whole playbook has completed and then it spits it out all at once. I need to be

Ansible regex_search/regex_findall

别等时光非礼了梦想. 提交于 2021-01-28 17:50:17
问题 I'm trying to parse the output of a command that returned a line like this (there's more output, but this is the line that I'm after): Remaining Time: 3 Minutes and 12 Seconds And when there is no time left it returns a line like this: Remaining Time: 0 Seconds I'd like to extract the amount of minutes and seconds, so I can feed it to GNU date -d. First I tried this: - name: determine how much time we have left set_fact: time_left: "{{ cmd_output.stdout | regex_search(time_left_regex, '\\1',

Ansible(五)j2模版

给你一囗甜甜゛ 提交于 2021-01-28 15:29:01
j2模版 在某些情况下,我们可以希望针对不同的主机生成不同内容的文件,可以使用j2模版实现这种功能。 J2模版的使用 - tasks: template: src: my.cnf.j2 dest: /tec/my.cnf J2模版语法 注释 {# context #} 变量 {{ var_name }} 条件判断 {% if mysql_version == 5.6 %} read_only=1 {% else %} read_only=1 super_read_only=1 {% endif %} 循环 简单循环 {% for item in list %} {{ item }} {% endfor %} 循环和条件判断 {% for item in list if not myuser == "root" %} User number {{ loop.index }} - {{ myuser }} {% endfor %} 更多语法可以查看: Template Designer Documentation 来源: oschina 链接: https://my.oschina.net/u/4255780/blog/4930070

Ansible(四)如何进行流程控制

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-28 13:28:21
在 ansible-playbook 中,也可以像其他编程语言一样进行条件判断、循环等流程控制。除此之外,还可以控制 task 的执行结果。 条件判断 WHEN 在 ansible 中,可以通过 when 语句来执行条件判断,只有符合条件,才会执行对应的 task 。 when 语句和 task 对齐,在 when 语句中,变量不需要使用 {{ }} 括起来。 常用判断条件 条件 示例 字符串相等 ansible_machine == "x86_64" 数值相等 max_memory == 512 小于 min_memory < 128 大于 min_memory > 128 小于等于 min_memory <=512 大于等于 min_memory >= 512 不等于 min_memory != 512 变量存在 min_memory is defined 变量不存在 min_memory is not defined 变量值为 true ( 1,True,yes 等价与 true ) memory_available 变量值为 false ( 0,False,no 等价与 false ) not memory_available 第一个变量值在第二个变量列表中 ansible_distribution in supported_distros 单条件判断 # when 示例

Ansible, k8s and variables

◇◆丶佛笑我妖孽 提交于 2021-01-28 11:43:05
问题 I'm using Ansible and the k8s module for deploying applications to an OpenShift cluster. In general this is working really well. However, when I try to set the port value, in a deployment config, using a value from a variable, things are not so happy. I have the following ansible task as an example: - name: Create app service k8s: name: "{{ name | lower }}" state: present definition: apiVersion: v1 kind: Service metadata: annotations: labels: app: "{{ name | lower }}" name: "{{ name | lower }

Are dashes allowed in dict keys in ansible?

笑着哭i 提交于 2021-01-28 07:10:30
问题 I have an issue with a playbook, and wonder if the issue is that some key names in the dictionary I use have a dash in them. Ansible is not clear wether this is allowed or not. I am using nmstatectl to get a json that describes the current network config on a RHEL8 host. The json output uses keys that have a dash in them, and I would like to use the output pretty much as is. The playbook: - name: check static route using nmstatectl hosts: rhv tasks: - name: collect network config command: cmd

Include vars from a file for multiple import_playbooks

北慕城南 提交于 2021-01-28 06:50:30
问题 This is an error using Ansible 2.7 I am trying to include a files with vars in it into my playbook that has multiple import_playbooks. I have 3 files. one with all the vars one with a playbook and a task one with an import_playbook My playbook: --- - name: Create CPG hosts: localhost tasks: - name: Create CPG "{{ cpg_name }}" hpe3par_cpg: storage_system_ip: "{{ storage_system_ip }}" storage_system_username: "{{ storage_system_username }}" storage_system_password: "{{ storage_system_password }

Ansible: Pass command arguments as a list

百般思念 提交于 2021-01-28 06:20:30
问题 I want to store multiple arguments in a variable as a list. vars: my_args: - --verbose - --quiet - --verify Then pass the list as quoted arguments to a command. The most obvious join filter doesn't work as I expected. It produces a single word containing all list elements as opposed to one word per list element: tasks: - command: printf '%s\n' "{{ my_args | join(' ') }}" ... changed: [localhost] => { "changed": true, "cmd": [ "printf", "%s\\n", " --quiet --verbose --verify " ], STDOUT: -

Docker NFS volume using Ansible

旧时模样 提交于 2021-01-28 05:48:33
问题 Given a simple example such as $ docker volume create --driver local \ --opt type=nfs \ --opt o=addr=192.168.1.1,rw \ --opt device=:/path/to/dir \ foo How can I do the same using Ansible? I tried for example - name: NFS volume mount docker_volume: driver: "local" driver_options: type: nfs o: "addr=192.168.1.1,rw" device: /path/to/dir volume_name: foo Which will create the volume without errors but it will fail when the volume is used with docker_container module. TASK [oracle-database :

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

ε祈祈猫儿з 提交于 2021-01-28 05:41:16
问题 I am trying to use ansible to deploy our system. I used expect module in yml file and try using ansible-playbook to run it and got this error: fatal: [192.168.100.132]: FAILED! => {"changed": false, "failed": true, "msg": "The pexpect python module is required"} Then I downloaded the pexpect-4.2.1 package from pypi.python.org and install it by "python setup.py install". But it doesn't work and error never changed. What should I do to deal with the error ? Some code from yml file: - name: auth