标签: ansible-playbook

Ansible 仅在远程主机上复制或移动文件

这应该有效,但没有,并给出以下错误(如下)。

我在这里这里阅读了几篇关于 stackoverflow 的帖子,但在这种情况下似乎没有一个好的答案。我真的希望我只是错过了一些愚蠢的东西,我已经在这里呆了几个小时了,所以请不要介意我的咆哮,但我需要发泄一下。

由于 ansible 2.3.0 无法仅在远程主机上执行复制/移动/重命名文件这样简单的操作,我的意思是谁会想要这样做?而且它也不能作用于 globs (*)(比如当你不知道要作用于哪些文件时),两步方法似乎是(我知道的)移动某些文件的唯一方法(仅在远程主机)。但即使这样也行不通。

migrate_rhel2centos.yml

---
- hosts: RedHat
  become: true
  become_user: root
  become_method: sudo
  vars:
    repo_dir: /etc/yum.repos.d
  tasks:
  - name: create directory
    file: path=/etc/yum.repos.d/bak/ state=directory

  - name: get repo files
    shell: "ls {{ repo_dir }}/*.repo"
    register: repo_list

 - debug: var=repo_list.stdout_lines

 - name: move repo files  
   command: "/bin/mv -f {{ item }} bak"
   args:  
     chdir: "{{repo_dir}}"
   with_items: repo_list.stdout_lines


#################################

TASK [get repo files]     

**********************************************************************
changed: [myhost]

TASK [debug]    
**********************************************************************
ok: …
Run Code Online (Sandbox Code Playgroud)

glob move ansible-playbook

2
推荐指数
2
解决办法
1万
查看次数

Ansible yaml语法失败

我有一个关于ansible的yaml文件

  # role: common
  # # common tasks
  # ---
    # #
  # # create default mariadb Audit db users
  # #
 -name: common | setup impactGroup group
 group: name=group system=no gid=510
 ignore_errors: yes
~ 
Run Code Online (Sandbox Code Playgroud)

我还在库存文件中定义了正确的服务器列表

当我执行ansible-playbook命令时,我得到以下错误

  /usr/bin/ansible-playbook -D /tmp/eabinay/test.yml -i /tmp/eabinay/dbServerInventory
  ERROR: parse error: playbooks must be formatted as a YAML list, got <type 'dict'>
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

1
推荐指数
1
解决办法
1万
查看次数

用sudo运行ansible playbook

我有一个剧本,我想用sudo运行它.这是我的ansible剧本:

site.yml

---
- name: Server
  hosts: node1
  sudo: yes
  roles:
    - dbserver
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到了这个:

ansible-playbook -i hosts site.yml

PLAY [Server] ***************************************************************** 

GATHERING FACTS *************************************************************** 
fatal: [node1] => Missing sudo password

TASK: [dbserver | installing server] ****************************************** 
FATAL: no hosts matched or all hosts have already failed -- aborting


PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/robe/site.retry

node1                      : ok=0    changed=0    unreachable=1    failed=0
Run Code Online (Sandbox Code Playgroud)

然后我在site.yml上添加ansible sudo pass:

---
- name: Server
  hosts: node1
  sudo_pass: ubuntu
  roles:
    - dbserver
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

ERROR: sudo_pass is …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

1
推荐指数
1
解决办法
1万
查看次数

Ansible - msg:没有匹配'$ item'的包

我需要设置我的服务器.我有以下的ansible剧本.

---

- hosts: webservers
  user: root
  sudo: yes
  tasks:
    - name: add nginx ppa
      action: apt_repository repo=ppa:nginx/stable state=present

    - name: install common packages needed for python application development
      action: apt pkg=$item state=installed
      with_items:
        - libpq-dev
        - libmysqlclient-dev
        - libxml2-dev
        - libxslt1-dev
        - mysql-client
        - python-dev
        - python-setuptools
        - python-mysqldb
        - build-essential
        - git
        - nginx

    - name: install pip
      action: easy_install name=pip

    - name: install various libraries with pip
      action: pip name=$item state=present
      with_items:
        - uwsgi

  handlers:
    - name: …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

1
推荐指数
1
解决办法
4318
查看次数

如何在ansible中循环主机名或IPS

我试图在ubuntu 14.04中使用ansible playbook设置和配置起搏器.

截至目前,我只是在1节点测试它.因此在hosts文件中我只保留了该节点的信息

[hostname]
1.2.3.4   ansible_ssh_private_key_file=/home/ubuntu/test.pem
Run Code Online (Sandbox Code Playgroud)

在剧本Yaml文件我试图安装以及配置起搏器

- hosts: all
  sudo: yes
  tasks:
    - name: install pacemaker
      apt: name=pacemaker state=present
    - name: install corosync
      apt: name=corosync state=present
    - name: install fence-agents
      apt: name=fence-agents state=present
    #- copy: src=corosync_start dest=/etc/default/corosync
    #- shell: update-rc.d -f pacemaker remove
    #- shell: update-rc.d pacemaker start 50 1 2 3 4 5 . stop 01 0 6 .
Run Code Online (Sandbox Code Playgroud)

在我的节点中正确安装.但是对于配置,我需要编辑/etc/corosync/corosync.conf,其中我需要指定我的主机地址来代替bindnetaddress.

假设在[hostname]部分下有超过1个条目有任何方式在ansible我可以在我的YAML文件中循环它们

我正在尝试使用sed命令来替换IP.但是,请你帮忙解决如何循环或打印Ips的问题.

我试过这样的

- hosts: all
  sudo: yes
  tasks:
    - debug: msg = "{{ ansible_hostname }}"
    - …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

1
推荐指数
3
解决办法
1万
查看次数

使用Ansible将文件从一台服务器复制到另一台服务器

我想使用Ansible将文件从一个服务器复制到另一个服务器.以下是示例

Server A ------> Server B
Server C ------> Server D
Run Code Online (Sandbox Code Playgroud)

我在服务器A上有一个文件,特别是要将该文件复制到服务器B,服务器C到D也是如此.将文件保存到目的地的文件夹是相同的.我可以为2或3台主机做这件事.但是我怎么能动态创建让我们说100个节点来复制特定的单个文件只分配给所需的服务器.

ansible ansible-playbook

1
推荐指数
1
解决办法
6802
查看次数

Ansible ec2_elb_lb HTTPS到HTTP错误

我已成功使用此剧本创建了一个ELB:

 - name: Create VPC network
      ec2_elb_lb:
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        name: "ElasticLoadBalancer"
        region: us-east-1
        state: present
        subnets: "{{ Subnet.SubnetId }}"
        listeners:
           - protocol: http
             load_balancer_port: 80
             instance_port: 80
      register: elb
    - debug: msg="{{ elb }}"
Run Code Online (Sandbox Code Playgroud)

但我还需要添加HTTPS入站和HTTP出站,因此我根据ec2_elb_lb模块示例添加了一个额外的侦听:

- name: Create VPC network
      ec2_elb_lb:
        aws_access_key: "{{ aws_access_key }}"
        aws_secret_key: "{{ aws_secret_key }}"
        name: "ElasticLoadBalancer"
        region: us-east-1
        state: present
        subnets: "{{ Subnet.SubnetId }}"
        listeners:
           - protocol: http
             load_balancer_port: 80
             instance_port: 80
           - protocol: …
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-web-services ansible ansible-playbook

1
推荐指数
1
解决办法
678
查看次数

如何使用ansible创建IAM用户,如文档中所示?

建立

我想使用Ansible来配置我的IAM用户,组和权限,但我甚至无法开始使用.我安装了Ansible(2.1.0)的开发分支,并尝试运行docs中示例中显示的简单播放.

site.yml

# Basic user creation example
tasks:
- name: Create two new IAM users with API keys
  iam:
    iam_type: user
    name: "{{ item }}"
    state: present
    password: "{{ temp_pass }}"
    access_key_state: create
  with_items:
    - jcleese
    - mpython
Run Code Online (Sandbox Code Playgroud)

我使用以下命令运行游戏:

$ ansible-playbook site.yml
Run Code Online (Sandbox Code Playgroud)

并收到以下错误:

错误

ERROR! playbooks must be a list of plays

The error appears to have been in '~/aws_kingdom/site.yml': line 2, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

1
推荐指数
1
解决办法
2332
查看次数

ansible - "when"条件不使用逻辑"AND"运算符

我正在尝试为开发人员编写ansible playbooks并为django应用程序测试env配置.然而,在ansible任务中使用条件时似乎存在问题.

在下面的代码中,任务2在任务1被更改时执行.它不检查第二个条件.

- name: Task 1
  become: yes
  command: docker-compose run --rm web python manage.py migrate chdir="{{ server_code_path }}"
  when: perform_migration
  register: django_migration_result
  changed_when: "'No migrations to apply.' not in django_migration_result.stdout"
  tags:
    - start_service
    - django_manage

- name: Task 2 # Django Create Super user on 1st migration
  become: yes
  command: docker-compose run --rm web python manage.py loaddata create_super_user_data.yaml chdir="{{ server_code_path }}"
  when: django_migration_result|changed and ("'Applying auth.0001_initial... OK' in django_migration_result.stdout")
  ignore_errors: yes
  tags:
    - start_service
    - django_manage
Run Code Online (Sandbox Code Playgroud)

每当更改Task1而不评估第二个条件时,就会运行任务2

"'Applying …
Run Code Online (Sandbox Code Playgroud)

yaml jinja2 ansible ansible-playbook

1
推荐指数
1
解决办法
8371
查看次数

为什么我的自定义Ansible模块失败了?

我正在学习ansible所以我写了一本我能想到的最简单的剧本和模块,但它失败了.

我的剧本

---
- hosts: demo
  tasks:
    - name: install demo
      action: install
Run Code Online (Sandbox Code Playgroud)

我的模块

echo "changed=True msg=OK"
Run Code Online (Sandbox Code Playgroud)

以下似乎很好:

  • bash脚本模式是755
  • playbook正确链接到模块

这是输出:

FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "changed=True msg=OK\r\n", "msg": "MODULE FAILURE", "parsed": false}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我怎样才能做到这一点?

ansible ansible-playbook

1
推荐指数
1
解决办法
3050
查看次数