ansible

is nested yaml inventory file for ansible supported?

对着背影说爱祢 提交于 2019-12-25 07:46:48
问题 I'm trying to use a yaml file as inventory file which looks like below: - prod: webserver: hosts: example1.com db_servers: hosts: example2.com example3.com - stag: webserver: hosts: example3.com It doesn't seem to work, and I couldn't find much info on ansible docs arounf yaml inventory file. Is the above supported? 回答1: No, this is not supported. You are supposed to have different inventories for production/testing. You can only define single dependency tree like this: webserver: hosts:

Error trying to create a new vm in ansible

 ̄綄美尐妖づ 提交于 2019-12-25 07:19:56
问题 I just started learning Ansible. It has been a pain so far. I have this code to create a new vm. I followed this tutorial. --- - hosts: localhost connection: local tasks: - vsphere_guest: vcenter_hostname:1.1.1.12 username: root password: pasword guest: newvm001 state: powered_on validate_certs: no vm_extra_config: vcpu.hotadd: yes mem.hotadd: yes notes: This is a test VM folder: MyFolder vm_disk: disk1: size_gb: 10 type: thin datastore: storage001 vm_nic: nic1: type: vmxnet3 network: VM

Adding new sudo user using ansible - “password”: “NOT_LOGGING_PASSWORD” message

旧巷老猫 提交于 2019-12-25 06:44:50
问题 I'm using Vagrant (Virtual Box provider) to setup a local Virtual Machine. I'm also using ansible and more specific ansible_local (Vagrant plugin) to deploy some tools into the VM. Initially I'm trying to create a new user following the ansible documentation. --- - name: Master Node hosts: 127.0.0.1 connection: local user: root vars_files: - vars/vars.yml vars: username: nikolas tasks: - name: Adding user user: name={{username}} shell=/bin/bash groups=root append=yes password={{pass}} sudo:

Ansible api详解

家住魔仙堡 提交于 2019-12-25 05:38:58
背景说明: Ansible api 2.x和Ansible 2.0之前的版本相差很大, 也复杂很多,在读官方文档以及测试之后,终于总结出了ansible api 2.x的用法, 并封装成类供外部调用 源代码在文章结尾处 效果图如下: 执行shell/module 结果: 执行playbook的结果: 一: 环境介绍: CentOS Linux release 7.7.1908 ( Core ) ansible-2.7.8-1.el7.ans.noarch 文档: 官方文档 来源: CSDN 作者: knight-zhou 链接: https://blog.csdn.net/knight_zhou/article/details/103683305

Pulling git repo to a vagrant box using ansible

旧时模样 提交于 2019-12-25 04:46:23
问题 Hi all I am trying to pull a repo from my github to a vagrant box via ansible, refering this github issue. I have registered an ssh from my host with the github. And below is the part in the playbook where I'm trying to pull; - name: install git apt: name=git - name: create the ssh public key file copy: src=/home/user/.ssh/id_rsa.pub dest=/root/.ssh/id_rsa.pub mode=0644 - name: create the ssh private key file copy: src=/home/user/.ssh/id_rsa dest=/root/.ssh/id_rsa mode=0600 - name: setup git

Ansible - Find max value and run action based on a result only on one host

半世苍凉 提交于 2019-12-25 04:45:33
问题 I have a group of hosts named "db" with number of nodes that may vary. Each node has a fact ("seqno") which is an integer number. I need to compare this fact among all hosts and choose maximum value, then run some actions on one (and only one) host that has this maximum value. In case of multiple nodes having the same value, first node should be chosen. I tried this approach: - name: find max seqno value set_fact: seqno_max={{ [hostvars[groups['db'][0]]['seqno'], hostvars[groups['db'][1]][

How to set vars into ansible inventory?

痴心易碎 提交于 2019-12-25 03:45:12
问题 In playbook I'm using variable {{excluded_service}}. I want to run ansible playbook from python and provide this variable. And I can't use external inventory script to provide this variable. I am using to create inventory: hosts = ["127.0.0.1"] inventory=ansible.inventory.Inventory(hosts) but I don't understand where I can add value of variable? My code, that works with external inventory script: import sys import os import stat import json import ansible.playbook import ansible.constants as

ansible read part of xml as string - not as dict / list

家住魔仙堡 提交于 2019-12-25 03:29:16
问题 I have a below mentioned xml: <?xml version='1.0' encoding='UTF-8'?>` <Envelope> <Body> <response> <timestamp>2018-11-01T15:18:44-04:00</timestamp> <content>` <element1>value1</element1> <element2>value2(/element2> <element3> <child1>c1</child1> <child2>c2</child2> </element3> </content> </response> </Body> </Envelope> I have to capture the content tag children in xml format only to encode it. when I use xml module to get the content and its descendants, captured as list of dictionaries. All

unable to assume role after enforcing MFA policy

回眸只為那壹抹淺笑 提交于 2019-12-25 01:38:39
问题 I created a new policy to enforce IAM user to setup MFA using the policy in this link https://docs.aws.amazon.com/en_pv/IAM/latest/UserGuide/reference_policies_examples_aws_my-sec-creds-self-manage.html Now the IAM user has AdministratorAccess already..so now with applying this force MFA policy now the user has 2 policies attached. The AWS managed policy AdministratorAccess and the new Managed policy i created Force_MFA now when i try to run ansible iwth module https://docs.ansible.com

Deploy Ansible project which include a docker-compose.yml

让人想犯罪 __ 提交于 2019-12-25 01:24:18
问题 I woud like to use Ansible to deploy one of my project (let's call it project-to-deploy ). project-to-deploy can be run locally using a docker-compose.yml file, which, among other things, mount the following volumes inside the docker-container . version: "2" services: database: image: mysql:5.6 volumes: - ./docker/mysql.init.d:/docker-entrypoint-initdb.d messages: image: private.repo/project-to-deploy:latest Nothing more useful here. To run the project: docker-compose up . I have created a