为了解决这个问题,我需要设置环境变量:
export LC_ALL="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)
有没有办法在全球范围内为剧本做到这一点?
我有一个输出哈希值的python脚本。我希望将该哈希通过管道传递到ansible脚本中的变量中。
Python命令看起来像这样-
#!/bin/python
import crypt
test= crypt.crypt('test', '$6$Som3S@lt$')
print test
Run Code Online (Sandbox Code Playgroud)
我的ansible剧本看起来像这样-
hosts: webservers
remote_user: test
become: yes
become_method: sudo
vars:
pass:
tasks:
- name: Run Python Password script
command: /home/test/userPW.py > pass
Run Code Online (Sandbox Code Playgroud)
谢谢
我有关于多行和Ansible剧本的问题:
我创建了一个非常大的线条的剧本,我需要剪切这一行以便更好地阅读.我怎么能这样做?
- name: 'Create VM Azure :-P '
shell: if ! grep {{ item }} /tmp/vm_{{ rgName }}; then azure vm create --vm-size {{ groups['item'][vmsize] }} --resource-group {{ rgName }} --name {{ item }} --location {{ location }} --admin-username {{ username }} --ssh-publickey-file {{ sshfile }} --storage-account-name {{ rgName | lower }} --os-type {{ groups['item'][type_os] }} --image-urn {{ image }} --data-disk-size {{ disksize }} --subnet-id {{ subnetid_key }} --nic-names {{ item }}; fi
with_items: groups['test']
Run Code Online (Sandbox Code Playgroud)
我想按照以下方式进行,但是在执行playbook时我遇到了一些错误
- name: 'Create …Run Code Online (Sandbox Code Playgroud) 我正在使用Ansible的查找功能在INI文件中查找值.这是文档中的示例:
- debug: msg="User in integration is {{ lookup('ini', 'user section=integration file=users.ini') }}"
Run Code Online (Sandbox Code Playgroud)
这是我的任务:
- set_fact: aws_access_var = "{{ lookup('ini', 'AWS_ACCESS_KEY_ID section=Credentials file=/etc/boto.cfg') }}"
Run Code Online (Sandbox Code Playgroud)
它们在语法上看起来相同但我的任务失败了:
fatal: [localhost]: FAILED! => {"failed": true, "msg": "template error while templating string: unexpected char u\"'\" at 18. String: \"{{ lookup('ini', 'AWS_ACCESS_KEY_ID section"}
Run Code Online (Sandbox Code Playgroud)
知道它有什么问题吗?
我有两个针对远程主机启动的剧本(10.233.84.58).当启动独立(ansible-playbook -i inventory.txt playbook.yml)时,它们工作正常.
第一个剧本包括第二个剧本,它是相同的,除了显然include:
---
- hosts: all
tasks:
- debug: msg="hello form playbook1"
# up to now the content is identical between playbook1.yaml and playbook2.yaml
# without the next line the playbook runs fine
- include: playbook2.yml
Run Code Online (Sandbox Code Playgroud)
当我跑playbook1.yml:
# ansible-playbook -i inventory.txt playbook1.yml (master?)
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [10.233.84.58]
TASK [debug] *******************************************************************
ok: [10.233.84.58] => {
"msg": "hello form playbook1"
}
TASK [include] *****************************************************************
fatal: [10.233.84.58]: FAILED! …Run Code Online (Sandbox Code Playgroud) 我有将用户提供给远程主机的剧本:
---
- hosts: webserver
remote_user: myuser
sudo: yes
tasks:
- name: Add ssh Users
authorized_key: user='ubuntu' key="{{ lookup('file', './keys/{{item}}.pub') }}"
with_items:
- user1
- user2
- user3
- user4
- user5
- user6
- user7
- user8
- user9
- user10
- user11
- user12
Run Code Online (Sandbox Code Playgroud)
这个单一任务需要110秒,这非常慢.
$ ansible-playbook -i ./inventory setup_ssh.yaml -vvv
Using /vagrant/ansible.cfg as config file
1 plays in setup_ssh.yaml
...
PLAY RECAP *********************************************************************
XXX.XXX.XXX.XXX : ok=2 changed=0 unreachable=0 failed=0
Wednesday 27 July 2016 07:38:39 +0000 (0:01:50.486) 0:02:00.054 …Run Code Online (Sandbox Code Playgroud) 我在(非常)干净的10.11.6安装上遇到了一个奇怪的问题.我已经安装了brew,zsh,oh-my-zsh,Lil'switch和1password(并且没有其他内容).我安装了ansible ...
brew install ansible
......这是成功的.然后我去了一个预先存在的(并且简单的疯狂)Ansible项目并做了...
ansible -m ping all
然后它让我输入我的SSH密码.我已恢复以前安装的密钥,但我之前没有进入服务器.我输入密码并且ansible返回...
$ ansible -m ping all
host1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
Run Code Online (Sandbox Code Playgroud)
然后我ssh进入服务器检查一切都很好,它连接没有任何问题.
然后我重新跑了...
$ ansible -m ping all
它又回来了......
host1 | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "MODULE FAILURE",
"parsed": false
}
Run Code Online (Sandbox Code Playgroud)
......这有点奇怪?它似乎在说它不能再找到python,尽管它第一次发现它?
$ which python 回报 /usr/bin/python
$ python --version 回报 Python 2.7.10
$ which …
嗨我想用ansible克隆一个项目,但我一直得到以下错误
ERROR! this task 'git' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta
The error appears to have been in '/vagrant/ansible/roles/rolename/tasks/main.yml': line 67, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- git: repo=ssh://git@git.example.sample.net:/component/exact/repo.git
^ here
The error appears to have been in '/vagrant/ansible/roles/rolename/tasks/main.yml': line 67, column 5, but may
be elsewhere in the …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用debugAnsible模块打印出std,如下所示:
---
- hosts: all
tasks:
- name: list files under /root folder
command: ls /root
register: out
- name: stdout
debug: var=out.stdout_lines
Run Code Online (Sandbox Code Playgroud)
从如何使用Ansible 2.0 Python API来运行Playbook的答案?,我可以用python代码运行Ansible playbook.
所以问题是如何out使用Ansible python api 获取此剧本中变量的内容?
我一直在尝试使用Ansible playbook为我的hosts文件添加主机名.我的Ansible游戏看起来如下,我的主机文件位于/etc/ansible/hosts:
- name: adding host playbook
hosts: localhost
connection: local
tasks:
- name: add host to ansible host file
add_host:
name: myvm.cloud.azure.com
groups: mymasters
Run Code Online (Sandbox Code Playgroud)
Playbook成功执行,但新主机名未添加到Ansible主机文件中.有人可以帮我这个吗?
ansible ×10
ansible-playbook ×10
ansible-2.x ×3
python ×2
git ×1
ini ×1
macos ×1
multiline ×1
yaml ×1