ansible

Ansible - skip undefined variable in dict

久未见 提交于 2021-01-05 10:38:09
问题 I`m using ipa_user module to setup users. There is variable passsword which force new password. For some users (when var is not in dict) I would like to skip it in iteration, but it always fail. This is snippet from my playbook. Ansible version is 2.7 task: - name: adding ipa users ipa_user: name: "{{ item.value.login }}" state: "{{ item.value.state }}" givenname: "{{ item.value.givenname }}" sn: "{{ item.value.surname }}" mail: "{{ item.value.mail }}" telephonenumber: "{{ item.value

Ansible - only last with_items being updated in file

谁说胖子不能爱 提交于 2021-01-04 09:51:28
问题 Using blockinfile: which is using with_items from an exernal file. When I run the playbook I can see all itmes being processed but the resulting end file only has the last item updated. Apologies, bit of a noob to this, so might be missing something obvious. Tried various permutations I have an external yaml config file with following contents - which is included as include_vars: yaml props file: ds_props: - prop: dataSource.initialSize=8 - prop: dataSource.maxActive=50 - prop: dataSource

Ansible - only last with_items being updated in file

拈花ヽ惹草 提交于 2021-01-04 09:48:19
问题 Using blockinfile: which is using with_items from an exernal file. When I run the playbook I can see all itmes being processed but the resulting end file only has the last item updated. Apologies, bit of a noob to this, so might be missing something obvious. Tried various permutations I have an external yaml config file with following contents - which is included as include_vars: yaml props file: ds_props: - prop: dataSource.initialSize=8 - prop: dataSource.maxActive=50 - prop: dataSource

Access variable in other play - Ansible

天大地大妈咪最大 提交于 2021-01-04 05:42:27
问题 Ansible Version: 2.4.2.0 From here and here, I was able write below playbook $ cat test.yml - name: Finding Master VMs hosts: all-compute-host remote_user: heat-admin tasks: - name: Getting master VM's hostname shell: hostname register: hostname_output - name: Access in different play hosts: localhost connection: local tasks: - name: Testing vars debug: var='{{ hostvars[item]['hostname_output']['stdout'] }}' with_items: groups['all-compute-host'] I don't want use gather_facts: true and access

Access variable in other play - Ansible

两盒软妹~` 提交于 2021-01-04 05:41:15
问题 Ansible Version: 2.4.2.0 From here and here, I was able write below playbook $ cat test.yml - name: Finding Master VMs hosts: all-compute-host remote_user: heat-admin tasks: - name: Getting master VM's hostname shell: hostname register: hostname_output - name: Access in different play hosts: localhost connection: local tasks: - name: Testing vars debug: var='{{ hostvars[item]['hostname_output']['stdout'] }}' with_items: groups['all-compute-host'] I don't want use gather_facts: true and access

Ansible笔记

和自甴很熟 提交于 2021-01-02 11:09:03
安装配置 服务端安装系统: CentOS-7 # 安装 epel 源 yum install -y epel-release # 安装 ansible, pywinrm 模块 yum install -y ansible python-pip pip install pywinrm # 取消添加指纹提示 sed -i 's/#host_key_checking/host_key_checking/' /etc/ansible/ansible.cfg # Ansible hosts cat > /etc/ansible/hosts <<EOF [linux:vars] ansible_ssh_user = USERNAME ansible_ssh_pass = PASSWORD [linux] 192.168.0.74 192.168.2.XX ansible_ssh_pass=USERNAME ansible_ssh_pass=PASSWORD [windows:vars] ansible_user = USERNAME ansible_password = PASSWORD ansible_port = 5985 ansible_connection = winrm ansible_winrm_server_cert_validation = ignore [windows]

自动化运维Ansible使用

删除回忆录丶 提交于 2021-01-02 11:06:33
自动化运维Ansible使用(按照文档步骤就可以操作成功)。 文档分别坐了安装Ansible,使用Ansible控制两台机器。 特别说明:前面做了pssh为什么还要做一个Ansible的文档,因为Ansible灵活多变,下面我列举下它的优势。 1、可以输入密码控制不用做免秘钥。 2、就算卸载hosts列表也可以单独控制一些机器,并可以对机器做分类。 #####跟着文档部署的时候一定要仔细看每一个字一定要一定要一定要(每一个字都很重要) 提示下大家再用ansible redis -m command 模块执行一些命令的时候有可能失败可以改成使用shell模块。 下面我做实验的时候用了两种方式远程控制 1、免秘钥方式 2、输入密码方式 #私自转载请联系博主否则必定追究版权 下方有微信 系统环境: IP 节点名称 192.168.182.150 admin 192.168.182.150 client-1 192.168.182.150 client-2 1、设置三个节点主机名 admin节点执行 [ root@localhost ~ ] # hostnamectl set-hostname admin [ root@localhost ~ ] # su client-1节点执行 [ root@localhost ~ ] # hostnamectl set-hostname client

Is there a way to override a template defined into an ansible galaxy role?

六眼飞鱼酱① 提交于 2021-01-02 07:56:37
问题 I'm trying to set up a server with ansible and I'd like to use this galaxy role. It defines a template that I'd like to customize, but I don't know how. Right now I defined the role into requirements.yml and I installed it using: ansible-galaxy install -r requirements.yml which installed the role somewhere on my system. I tried by recreating the folder tree into my repository where I store my playbooks: roles |- ansible-role-passenger |- templates |- passenger.j2 but it does not work. When I

Run only one task and handler from ansible playbook

此生再无相见时 提交于 2021-01-01 07:02:06
问题 How can I run a single task from an Ansible playbook and the handler that gets notified when that task completes successfully, while skipping all other tasks in the relevant playbook? Currently I execute the following: ansible-playbook --start-at-task "task1" --step -K -i hosts playbook.yml and then press Ctrl + c after the task has finished. This will also skip the handler however. I know I can add a tag to the task and use that, as in How to run only one task in ansible playbook?, but I

Terraform local-exec Provisioner to run on multiple Azure virtual machines

前提是你 提交于 2021-01-01 06:45:29
问题 I had a working TF setup to spin up multiple Linux VMs in Azure. I was running a local-exec provisioner in a null_resource to execute an Ansible playbook. I was extracting the private IP addresses from the TF state file. The state file was stored locally. I have recently configured Azure backend and now the state file is stored in a storage account. I have modified the local provisioner and am trying to obtain all the private IP addresses to run the Ansible playbook against, as follows: